Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added 'oData._aData.DT_RowData' to set <tr> HTML5 'data-*' custom attributes #45

Closed
wants to merge 1 commit into from

2 participants

@heruan

A more generic way to set non-data properties could be jQuery's $(<tr>).prop(oData) function.

@DataTables
Owner

This is quite a nice idea (although note that changes should be made in the media/src directory since jquery.dataTables.js is now a generated file :-) ). However, what is the benefit of doing this over simply access the data (DT_RowData) through fnGetData (or the new _ function in 1.9)? It looks like it be basically doing the same thing, but a slightly different method (this way is perhaps more "jQuery" like).

@heruan

I forgot to mention that my commit would be useful to set <tr> (data-)properties with an AJAX server response.
It would be also useful to have a mean to set <td> (data-)properties by the server response.
I don't know the new _ function in 1.9, I'll give it a look!

@DataTables
Owner

In fairness the new _ function is really new (it will be in beta 3 :-) ). It is basically the same as the $ function ( http://datatables.net/docs/DataTables/1.9.beta.2/#$ ) but gives the data object for a row rather than the node.

Does the jQuery data method also set the data- properties? I think I need to read up a bit more about what this provides, but I do like the look of it :-)

Allan

@heruan

I was unclear again! The jQuery data method gives access to the jQuery-element's data object, but initializes it by reading HTML5 data-* properties; thus, it doesn't modify the markup. To add actual data-* properties we could use the prop method.

@DataTables
Owner

Been thinking about this a fair bit recently, and I don't think I'm going to include it just yet, due to the fact that it is duplicating (to some extent) the internal data store that DataTables uses and the fnGetData / _ functions. However, I am very much open to introducing this in future if there is a benefit over the fnGetData / _ functions or there are a couple of other requests for it.

Leaving the issue open for the moment to allow others to comment on it.

@heruan

I understand, it's okay! Thank you for thinking about it for a while. Right now I'm using this approach to send <tr> properties in the JSON response, do you have any suggestion on doing that with fnGetData/_ functions?

@DataTables
Owner

Quick update: Considering this for DataTables 1.10. Depends a little bit on how I get on with using attributes for sorting.

Until then, in answer to the last question (really sorry about the massive delay) - you can use orthogonal data as described here: http://datatables.net/blog/Orthogonal_data

@DataTables DataTables referenced this pull request
Closed

additional information #7

@DataTables DataTables referenced this pull request from a commit
@DataTables New: HTML5 data-* attributes for the TR can be set using DT_RowData
property

- Extending the funtionality of DT_RowId and DT_RowClass, this commit
  adds DT_RowData which utalises jQuery's `$().data()` method to set
  HTML5 data-* attributes, which can be useful for additional meta data.

- This is some what complimentary to using objects as the data source
  where you could just use row().data() to get the data, but this is
  effectively an orthogonal way of getting the data and might be useful
  for existing Javascript libraries.

- It should be noted that the data-sort and data-filter work I'll be
  doing for v1.10 shortly will not interact with this method, that will
  be DOM sourced data only, while this is Ajax / Javascript based only.
  However, if you do want to use data from this source for filtering /
  sorting, its easy to do with `data` - `data: 'DT_RowData.sort'` for
  example.

- This fixes issue #45.
20949ae
@DataTables
Owner

I've finally got around to adding this, exactly as is in 20949ae which will be released as part of v1.10. This is part of DataTable's move to be able to make more use of HTML5 as part of v1.10 :-).

Thanks for the request for this to be added! I might not be the quickest, but I do get there :-)

@DataTables DataTables closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2012
  1. @heruan
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 media/js/jquery.dataTables.js
View
7 media/js/jquery.dataTables.js
@@ -994,7 +994,12 @@
{
$(oData.nTr).addClass( oData._aData.DT_RowClass );
}
-
+
+ if ( oData._aData.DT_RowData )
+ {
+ $(oData.nTr).data( oData._aData.DT_RowData );
+ }
+
/* Process each column */
for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
{
Something went wrong with that request. Please try again.