I'm trying to render a DataTable that automatically inserts and id to each row.
According to http://datatables.net/release-datatables/examples/server_side/ids.html and I understood ok, if I pass a DT_RowId "column" with each row, it should do it automatically.
I'm using the sample PHP they provide here: http://datatables.net/release-datatables/examples/data_sources/server_side.html
I made a MySQL View to have a dynamic table which turns the table index into a column named DT_RowId and added to the $aColumns variable so it outputs in the JSON.
The value is printed in the JSON but nothing happens. I'm 99% sure it's because the PHP code they provide doesn't echo the name of the column
In the example the JSON should be:
"aaData": [
{
"0": "Gecko",
"1": "Firefox 1.0",
"2": "Win 98+ / OSX.2+",
"3": "1.7",
"4": "A",
"DT_RowId": "row_7",
"DT_RowClass": "gradeA"
}, { ... }
but the PHP outputs a keyless
"aaData": [
{
"Gecko",
"Firefox 1.0",
"Win 98+ / OSX.2+",
"1.7",
"A",
"row_7",
"gradeA"
}, {...}
Seeing that I thought "how is the client-side javascript supposed to know the last column in the row is DT_RowId?". So I edited the PHP to output the JSON with the key data as in their example and I get:
{
"sEcho": 1,
"iTotalRecords": "4",
"iTotalDisplayRecords": "4",
"aaData": [
{
"Nombre": "Some Name",
"username": "some username",
"Email": "some email",
"lastModified": "0000-00-00 00:00:00",
"lastLogin": "2012-02-23 12:04:55",
"rolname": "Some string",
"DT_RowId": "2"
}, {...},{...},{...} ] }
but I get an alert saying "DataTables warning: Requested unknown parameter '0' form the data source for row 0"
My JSON is formatted like theirs and I'm using
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/id.php"
so I don't know why it's not a valid JSON for the DataTable to render. I may be missing something stupid but I'm stuck here.
Thanks for any help