how to add uniq id to row

how to add uniq id to row

lleminglleming Posts: 6Questions: 0Answers: 0
edited February 2014 in General
I have data returned in json format from server side. Problem is once row selected how to get data for this row.
Examples in documentation says to traverse in the row, which is useless because i don't display all data in each row.

There is a method fnGetData which return aoData (full set of data), but data identified by "id" property. That means, I have to keep somewhere in row information about id and tuple shown in the row.
I did try to hide it in span element in first column but it break visual style when column selected since first parent not a tr element any more.
I did try to use hide column with id inside which is as well did not work. It break table, or show error message that no data for column 0, or just ignore/remove column from table with id. (i really i cant understand why datatables removes column which is marked as "bVisible" :false if i can just do not include it in column definition and it will behave same)

Any ideas??

Only solution i found for now is to add fake node into each cell so cell value will be wrapped in span element, and when row is selected use second parentNode to get into row element.

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    > Problem is once row selected how to get data for this row.

    There are lots of ways :-). How is the row selected? If by a class name then you could do:

    [code]
    var data = table._( 'tr.selected' );
    [/code]

    which will put an the data for the selected rows into the variable `data` .

    > There is a method fnGetData which return aoData (full set of data)

    You can also pass in a node - `table.fnGetData( $('#myRow')[0] );` .

    Better yet is the new API in DataTables 1.10 you very simply do: `table.row( '#myRow' ).data();` . No mucking around. 1.10 should go into beta today.

    > i really i cant understand why datatables removes column which is marked as "bVisible" :false

    Because setting them to `display: none` causes cross browser display problems. Most browsers work okay with it, but not all (the older ones mainly). Thus, DataTables removes the elements from the DOM.

    Can you
  • lleminglleming Posts: 6Questions: 0Answers: 0
    i feel not comfortable about fnGetData. I cant understand how it get data from row, what if set of data in the certain row is not uniq in table?
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    fnGetData, in my example above, is getting the data based on the row node (i.e. the `tr` element). That is unique. If the data it is getting is not unique in the table, then you have multiple records which contain the same data, but fnGetData, with a row node passed in will always give the data for that row.

    Allan
  • lleminglleming Posts: 6Questions: 0Answers: 0
    thanks. that clarifies everything.
This discussion has been closed.