Dilemma in HTML colums and serverside processing

Dilemma in HTML colums and serverside processing

bozdenbozden Posts: 10Questions: 0Answers: 0
edited November 2013 in DataTables 1.9
Hi,

I started to use Ajax on all my DTs, using a slightly modified version of your SQL example. The problem is I want to use the last column of every table for HTML/JS driven buttons. For 3 database columns I use 4 TD's in DT HTML. On the other hand the PHP file returns a JSON for 3 colums, which causes the famous error as one column is missing:
[code]DataTables warning (table id = 'mytable'): Requested unknown parameter '3' from the data source for row 0[/code]
The JSON code is:
[code]{
"sEcho":1,
"iTotalRecords":"1",
"iTotalDisplayRecords":"1",
"aaData":[
[
"1",
"Ana Bina",
"Ana m\u00fcze binas\u0131"
]
]
}
[/code]

To correct this error one solution is to add a blank for the missing column in JSON. To do that I changed the last part of PHP code to this:

[code]
while ( $aRow = mysqli_fetch_array( $rResult ) ) {
$row = array();
for ( $i=0 ; $i

Replies

  • bozdenbozden Posts: 10Questions: 0Answers: 0
    I solved this by modifying the PHP file and adding the HTML/JS to above given "else" structure. Beware, JSON does not encode single quotes (by definition), so the JS breaks. I moved the JS to an external JS file and just called it.

    The only problem with this approach is that the Ajax call now returns more data and thus slows the rendering.
  • allanallan Posts: 63,234Questions: 1Answers: 10,417 Site admin
    Another way is to use mData set to null and then sDefaultContent to give static content to the cell or mRender for dynamic content.

    Allan
  • bozdenbozden Posts: 10Questions: 0Answers: 0
    I had to pass the primary key to the JS function as a parameter. I don't know how to do that in jQuery :(
  • allanallan Posts: 63,234Questions: 1Answers: 10,417 Site admin
    Assuming your primary key is in the row's data you can access it using mRender as a function:

    [code]
    mData: null,
    mRender: function ( data, type, row ) {
    return row.id;
    }
    [/code]

    Assuming the primary key is an object property called `id` .

    Allan
This discussion has been closed.