Skip to content
This repository

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

wants to merge 1 commit into from

2 participants

Giovanni Lovato Allan Jardine
Giovanni Lovato

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

Allan Jardine

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).

Giovanni Lovato

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!

Allan Jardine

In fairness the new _ function is really new (it will be in beta 3 :-) ). It is basically the same as the $ function ($ ) 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 :-)


Giovanni Lovato

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.

Allan Jardine

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.

Giovanni Lovato

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?

Allan Jardine

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:

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

- 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

- This fixes issue #45.
Allan Jardine

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 :-)

Allan Jardine DataTables closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 23, 2012
Giovanni Lovato heruan Added 'oData._aData.DT_RowData' to set <tr> HTML5 'data-*' custom att…
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 6 additions and 1 deletion. Show diff stats Hide diff stats

  1. +6 1 media/js/jquery.dataTables.js
7 media/js/jquery.dataTables.js
@@ -994,7 +994,12 @@
994 994 {
995 995 $(oData.nTr).addClass( oData._aData.DT_RowClass );
996 996 }
997   -
  997 +
  998 + if ( oData._aData.DT_RowData )
  999 + {
  1000 + $(oData.nTr).data( oData._aData.DT_RowData );
  1001 + }
  1002 +
998 1003 /* Process each column */
999 1004 for ( var i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
1000 1005 {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.