Why don't I get an ID in my row?
Why don't I get an ID in my row?
Can anyone help me? I'm new to this. I've messed with this for several days now. I'm using JSON. All of my data looks good and fills the table. I don't seem to have an ID attached to the row when I go to do an update. I thought it was supposed to ASSUME the row ID was the first column of data. Here is my stripped down code. Is there something wrong with my JSON String????
var oTable = $('#myDataTable').dataTable({
"bPaginate": false,
"bAutoWidth": true,
"aaData": data,
"aoColumns": [
{"mDataProp": "id", "sTitle": "ID" },
{"mDataProp": "field_name", "sTitle": "Field Name" },
]
}).makeEditable({
sUpdateURL: "/MyWebService.asmx/DoQuestionUpdate",
aoColumns: [
null, // AUTO INCREMENT QUESTION ID (unique id to make updates)
{}, // field_name
]
var oTable = $('#myDataTable').dataTable({
"bPaginate": false,
"bAutoWidth": true,
"aaData": data,
"aoColumns": [
{"mDataProp": "id", "sTitle": "ID" },
{"mDataProp": "field_name", "sTitle": "Field Name" },
]
}).makeEditable({
sUpdateURL: "/MyWebService.asmx/DoQuestionUpdate",
aoColumns: [
null, // AUTO INCREMENT QUESTION ID (unique id to make updates)
{}, // field_name
]
This discussion has been closed.
Replies
Prior to creating the datatable, declare and initialize the variable i. In your datatable initialization, add 'fnRowCallback' and set the unique id for the row.
[code]
var i = 0;
...
'fnRowCallback': function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$(nRow).prop('id', 'row-' + i++); // assign a unique id to each row
[/code]
DataTables does not do that. If you want the ID set you need to use the DT_RowId parameter or set it using a method such as acedanger suggests.
Allan