How to assign unique id attribute to each table row of a CGridView? - yii

I am attempting to assign a unique id to each table row in Yii's CGridView.
Preferably something like $data->id from the database table.
I have been unsuccessful at adding an id attribute to each rendered <tr>.
Any suggestions would be most appreciated.

CGridView have an option called 'rowHtmlOptionsExpression' , you can declare like the followings to assign row an id
'rowHtmlOptionsExpression' => 'array("id"=>$data->id)',
It's better than hacking into 'rowCssClassExpression'
Good luck !

Modern solution (since Yii 1.1.13)
This is now possible to do using the rowHtmlOptionsExpression attribute, which allows assigning arbitrary HTML attributes to each rendered table row. For example:
'rowHtmlOptionsExpression' => '["id" => $data->id]'
Original answer (earlier versions)
Not directly possible because CGridView does not support it, but there are a couple of straightforward solutions that you can try.
Subclass CGridView (good)
Simply create your own class MyGridView extends CGridView and override the renderTableRow method to spit out ids on every row. Have a look at the stock implementation, which does for the class attribute exactly what you 'd like to do for the id attribute.
Use a CSS class instead (not so good)
Speaking of class attributes, the rowCssClassExpression property can be used to dynamically generate classes out of the box. IMHO this is a bad workaround, but it's there.

You could extend CGridView to add that functionality.
or be a bit hacky with rowCssClassExpression.
'rowCssClassExpression' => '\'" data-id="\' . $data->rowID'

Try the information I posted here:
How to set key value in CGrideView when grid is populated from table-view
In essence, as long as your dataprovider to the CGridview provides the data->id in a form that it understands, it will auto handle the $data->id stuff for you automatically so that it's easily available to javascript.

CGridView.rowHtmlOptionsExpression is undefined
I don't think that we can use rowHtmlOptionsExpression

Related

How can we make an Item in socialengine?

I know how to get an item of the particular table. Like for user we can have
$userItem = Engine_Api::_()->getItem("user", $userId);
or for a custom table
$customItem = Engine_Api::_()->getItem("custom", $customeId);
I want to know the code or method how can I make my $customItem to work the same way as $userItem works for users table. So that I can get data or manipulate the data of custom table
Thanks for your help. :-)
You can achieve that by creating a model. Check how it's done in /application/modules/User/Model. There is User.php file that declares User_Model_User and methods available for User such as getTitle, get Href etc.
You may use similar approach for your custom item. You will also need to create a file similar to /application/modules/User/Model/DbTable/User.php to declare table for your custom items.

Is OOP really helping?

I am trying to create a simple module in Drupal 8 and it looks like what was really easy in Drupal 7 is now unbelievably complicated. It can be done with help of StackOverflow and Google, however, one example:
Getting field values from node like this:
'name' => $node->get('title')->getValue(),
'body' => $node->get('body')->getValue(),
'image' => file_create_url($node->field_fotografia->entity->getFileUri()),
Why is the way of getting image field different from the title and body? How do I know what way to use and how will I know in future if there is any other way for other type of field?
the logic is quite simple
$node->get('body')->getValue();
means: get property value of field "body"
D7 equivalent is
$node['body'][$language][$index]['value];
which is straigh forward
now the other example
$node->field_fotografia->entity->getFileUri()
means: get property uri of entity stored in field "field_fotografia" since the image is not a property value but a separate entity; actualy I believe that $node->get('field_fotografia')->getValue() returns the image id which make sense. Same model applies for all entity references (multifield, paragraphs, other nodes, etc).

Is there a way to dynamically change the class of a single header in slick-grid 1.4.3?

I noticed that the latest version of slick-grid has a 'headerCssClass' attribute on the column, which would work great, except I am restricted to using slick-grid version 1.4.3.
I am extending slick-grid so as to add multiple column sort functionality and will need to set the class of each sort header accordingly. So, to re-iterate the question, does anyone know of a way to dynamically change the class of any given header in slick-grid 1.4.3?
I don't really love this solution, as it is not preferred to use JQuery to modify the slick-grid, but here goes:
var headers = $('.slick-header-columns').get(0).children;
remove any non-default class information from all the headers(i.e., $(headers).removeClass('slick-header-column-sorted'))
iterate through the columns of the slick-grid and use JQuery to add a class at the wanted column index
var header = headers[wantedColIdx];
$(header).addClass('yourClass');
I think you can do this with jQuery.
Add a blank css class with some name.
Then you can call addClass and removeClass to change the class dynamically.
http://api.jquery.com/addClass/
http://api.jquery.com/removeClass/
i.e.
jQuery('.my-class').addClass('new-header-class');

How to pass a field that is an array list in a java bean, within a JasperReports?

Could some indicate a working example or a snippet of code for JasperReports regarding ArrayList as a Field in a javabean datasource.
I have a List of Employees. Each Employee has a name field, and an array of Phone with type and number as its fields.
Do i use a subreport for Phones I have not found a working example? Cant seem to compile subreport_jasper file?
Do i use a list component instead...
<c:list ...>
<datasetRun subDataset="Addresses">
<datasetParameter name="Phone">
<datasetParameterExpression><![CDATA[$F{Phone}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
This does seems to work either?
Thank in advance
I wrote this article while working with MongoDB. It deals with handling fields that are collections. It should be exactly what you need. (You can just ignore the MongoDB part.)
The key idea is that you use this to pass data to a List or Table or Subreport:
new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($F{PhoneArray})

Displaying Custom Attributes in Documentum - Webtop

I am following an article that explains how to use the ICustomAttributeDataHandler class.
I am creating a custom column for the inbox screen, but the problem is that the value I set for my custom attribute is not being reflected on the screen.
As a test I am changing the task name to "whoKnows". But this code is not effecting what is output on the screen:
ICustomAttributeRecordSet.setCustomAttributeValue(i, "taskName", "whoKnows");
(I am able to print debug lines from my custom class when the inbox is viewed, so I know my code is being run.)
Someone on the comments of that article wrote:
the user must call the
"setCustomAttributesInQuery() method
on the dataprovider passing in a
string array of the custom attributes
...what does that meen? Could this be my problem?
thanks.
To be honest, I have already used Webtop, but just as an user. I found a post in the dm developer discussion group that can be useful, though:
For creating a custom column in the
doclist you dont need to go through
this complex procedures. You can use
custom attribute datahandlers for
this.
First in your object list component xml file add your custom column
definition in the "columns" tag. You
can even add static columns instead of
the documentum attributes.
Now create a class which implements the ICustomAttributeDataHandler.
Implement the default the methods getRequiredAttributes and the getData
function.
In getRequiredAttributes add attributes of the object that you are
looking for.
In your getdata method retrieve each row and then based on the
attribute that you see, just set the
value that you want to. 6) Finally
define your class in the app.xml file
There is a section in WDK developement
guide regarding
ICustomAttribuetDataHandlers. Look for
the topic named "Adding custom
attributes to a datagrid".
I'm not sure if this is the final solution, but I hope it helps!
To answer you question about setCustomAttributesInQuery()
every datagrid in WDK is backed by an underlying data provider. You can get this proivder by using the following code.
Datagrid datagrid = (Datagrid)getControl("doclist_grid",com.documentum.web.form.control.databound.Datagrid.class);
DataProvider dp = datagrid.getDataProvider();
Once you've done that, you can call
dp.setCustomAttributesInQuery(myArr);
I'm not actually sure if this is part of the solution to your problem, but you could try this and see where it gets you.
You have to configure the inbox component.
if using classic view, go to inboxlist component and add your custom attribute.
<column>
<attribute>CustomAttributeName</attribute>
<label>Custom Attribute Label</label>
<visible>true</visible>
</column>
Your custom attribute has to be in a custom type that is a sub type of dmi_queue_item, because inboxlist shows only dmi_queue_item objects.
Hope this helps,
Regards,
Tejas.
This may be a non-issue, but based on your code, I can't tell if you're doing this:
ICustomAttributeRecordSet.setCustomAttributeValue(i, "taskName", "whoKnows");
or this:
ICustomAttributeRecordSet rs;
rs.setCustomAttributeValue(i, "taskName", "whoKnows");
You should be calling the setCustomAttributeValue method on the rs object instance, not on the interface.