Why don't I get an ID in my row?

Why don't I get an ID in my row?

jaultjault Posts: 5Questions: 0Answers: 0
edited May 2012 in General
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
]

Replies

  • acedangeracedanger Posts: 5Questions: 0Answers: 0
    edited May 2012
    I create a unique row id

    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]
  • jaultjault Posts: 5Questions: 0Answers: 0
    I was wanting the unique id of the row to match the unique ID of the corresponding row in the database. I thought I read that it would take the value in the first column automatically as the row ID. Am I wrong?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > I thought I read that it would take the value in the first column automatically as the row ID. Am I wrong?

    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
  • jaultjault Posts: 5Questions: 0Answers: 0
    Got it. Thank you.
This discussion has been closed.