Accessing contents of hidden column

Accessing contents of hidden column

neburtonneburton Posts: 63Questions: 6Answers: 0
edited July 2010 in General
Firstly, datatables is fantastic and I'm using it a lot lately. Thanks for your efforts.

I'm using the context menu plugin (http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/) to give me some menu options when I right click on a row.

I'm having difficulty storing a unique ID on each row, that I can access with my context menu. I've managed to do this previously by putting the unique ID in a REL attribute of a link within a TD within the row, but in this instance i want the context menu to work across the whole row and I've applied a class to the row using :

[code]"fnRowCallback": function( nRow, aData, iDisplayIndex )
{
$(nRow).addClass('noteMenuTrigger');
return nRow;
}[/code]

I've generating my table using JSON/AJAX and I thought that I could store the uniqueID for my table in the first TD of the row then hide it. The context menu plugin provides the element that was clicked as "el" and if I use [code] rowid = $('td:first',el).html();[/code] I can access my unique row id from the database table, but as soon as I set [code]{ "bVisible": false }[/code] this renders that data inaccessible.

How can I access this invisible data, or can you recommend an alternative way of storing unique row data somewhere in the row that I can access.

Replies

  • cjordancjordan Posts: 1Questions: 0Answers: 0
    Disappointed that there's no response to this question. I've got a similar need to store some data on each row, that the user doesn't need to see. Clicking on the row will send that data to the server for a look-up... ugh. I guess I'll keep searching the forums to see if this was done anywhere else.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    instead of using jquery to get the cell contents (data) of a hidden row, use the DataTable API function fnGetData

    [code]
    console.log(oTable.fnGetData( 0 )[4]);
    [/code]

    hey Allan, your API says funGetData(iRow, iCol) should work, but I'm getting errors unless I omit the column
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    The original is a really old post now (yikes - sorry I didn't answer it at the time!) but basically the answer is in DataTables 1.8's mDataProp options: http://datatables.net/blog/Extended_data_source_options_with_DataTables . With this you can use a Javascript object for each row, and store whatever information you want it it, and pull out whatever you need to display the table with mDataProp.

    @fbas: Thanks for the heads up! I'll check that out and correct to the way I originally intended (which I forget at the moment...).

    Regards,
    Allan
This discussion has been closed.