DT_RowId in a 2-dim static array?
DT_RowId in a 2-dim static array?
fburleigh
Posts: 3Questions: 0Answers: 0
Suppose DataTables is given a 2 dimensional array as its data source:
aDataset=[
["item 1", 1],
["item 2", 2]
...
];
Then let's say we create the table like this:
$('#datadisplay').dataTable( {
bFilter:false,
bInfo:false,
iDisplayLength:25,
bLengthChange:false,
aaData:aDataset,
aoColumns:aColumns
} );
What would I do to give each row a DT_RowId? I tried:
{DT_RowID:"item 1"} and a programmed aDataset[i]["DT_RowId"]=
and got what I thought I needed (in the second case) but, alas, that's not what DT 1.8 wants.
Thanks.
aDataset=[
["item 1", 1],
["item 2", 2]
...
];
Then let's say we create the table like this:
$('#datadisplay').dataTable( {
bFilter:false,
bInfo:false,
iDisplayLength:25,
bLengthChange:false,
aaData:aDataset,
aoColumns:aColumns
} );
What would I do to give each row a DT_RowId? I tried:
{DT_RowID:"item 1"} and a programmed aDataset[i]["DT_RowId"]=
and got what I thought I needed (in the second case) but, alas, that's not what DT 1.8 wants.
Thanks.
This discussion has been closed.
Replies
1. Use objects
2. Assign DT_RowId to the array as a property before giving it to DataTables (i.e. pre-process it)
3. Add the ID using standard DOM methods in the draw callback (fnDrawCallback)
Allan
1. Object in each row: aDataset = [[1, 2, ..., {DT_RowId:value}], ... ];
2. Preprocess javascript 2-dim array before making DT -- for each row i: aDataset[i].DT_RowId="value";
console.log() on 2. seemed like it ought to have "worked" to me.
I'm clearly overlooking something.
2. I would have expected to work as well. Can you link us to a page with that code which isn't working?
Allan
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
Allan
I'll try to post some JSON as well.
{"iTotalDisplayRecords":31,"iTotalRecords":31,"aaData":[{"3":"","2":"1 Years","1":"United States","0":"CDU2B","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"111","DT_RowId":"0"},{"3":"","2":"2 Years","1":"United States","0":"CDU2B","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"100","DT_RowId":"9"},{"3":"","2":"5 Years","1":"United States","0":"CDU2B","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"94.35","DT_RowId":"13"},{"3":"","2":"3 Years","1":"United States","0":"CDU2B","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"94.35","DT_RowId":"17"},{"3":"","2":"4 Years","1":"United States","0":"CDU2B","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"94.35","DT_RowId":"20"},{"3":"","2":"2 Years","1":"United States","0":"CSU00","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"47.7","DT_RowId":"1"},{"3":"","2":"1 Years","1":"United States","0":"CSU00","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"53","DT_RowId":"5"},{"3":"","2":"3 Years","1":"United States","0":"CSU00","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"45.05","DT_RowId":"6"},{"3":"","2":"4 Years","1":"United States","0":"CSU00","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"45.05","DT_RowId":"16"},{"3":"","2":"5 Years","1":"United States","0":"CSU00","7":"","6":"01/07/2008 01:00:00","5":"USD","4":"45.05","DT_RowId":"26"}],"sEcho":"1"}
And when I look at the displayed HTML it says:
I am using JEditable and the DataTable/Editable plugin. Looking at the source, that doesn't seem to affect it. Stepping through the DataTables source, seems to show it correctly setting the ID:
oData.nTr.setAttribute( 'id', oData._aData.DT_RowId );
Looking at the example you suggest (http://www.datatables.net/beta/1.8/examples/server_side/ids.html) I see yours working, but I don't think I can see a difference.
Allan
The odd bit is that even though the DT_RowID I'm returning is "1", the tr.ID field says "CDU2B".
Unless I've misunderstood, the tr.ID field should equal the DT_RowID field?
Allan
The problem I'm seeing is that I'm using the two jeditable plugins - and when I perform edits on Page 2, the "sUpdateURL" callback doesn't pass me a page number, and the rowID is the row number on THAT page, not the accumalative row number - so I think I'm applying edits to the first page as the rowID is 5 or so.
I still can't get DT_RowID to be used on the web page. All the examples on the website aren't implemented using a server call, so I think you avoid seeing the sUpdateURL page number problem.
I'll keep searching for clues, but if anyone comes up with any suggestions, I would be very eager to try them out.
[code]
$(oTable.fnGetNodes()).each(function () {
var position = oTable.fnGetPosition(this);
var id=oTable.fnGetData(position)[0];
properties.fnSetRowID($(this), id);
}
);
[/code]
Currently testing to see if this code would be better:
[code]
$(oTable.fnGetNodes()).each(function () {
var position = oTable.fnGetPosition(this);
var data = oTable.fnGetData(position);
var id;
if ( typeof data.DT_RowId != 'undefined' ) {
id = data.DT_RowId;
} else {
id = data[0];
}
properties.fnSetRowID($(this), id);
}
);
[/code]
Hope the release goes smoothly :-)
Allan
http://code.google.com/p/jquery-datatables-editable/issues/detail?id=63