DataTables custom column parameter for order - Ajax

DataTables custom column parameter for order - Ajax

PuzoPuzo Posts: 1Questions: 1Answers: 0
edited December 2015 in Free community support

Is it possible to pass different type of column/cell content for sort type for all columns/cells? I don't want to define for which column this rule apply. I call the same DataTable object on multiple tables with different structure.

$(".dataTable").DataTable({
"ajax": ajaxURL,
"deferRender": true,
"lengthMenu": [[5, 15, 20, 50, -1],[5, 15, 20, 50, "All"]],
"pageLength": 15,
"columnDefs": [{
     "targets": "_all",
     "data": null,
     "render": {"_": "plain","filter": "filter","display": "plain"}
     }]
});
{"data":[
    [
       {"plain":122,"filter":122},
       {"plain":"waiting","filter":0},
       {"plain":"27.12.2015","filter":"1451174400"}
    ],[
       {"plain":123,"filter":123},
       {"plain":"approved","filter":1},
       {"plain":"27.12.2015","filter":"1451174400"}
    ] ...
]}

What am I doing wrong?

Regards, Mario

This question has an accepted answers - jump to answer

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    If you are trying to sort the "plain" column, based upon the "filter" column, then yes, you can do that using the orderdata().
    https://datatables.net/reference/option/columns.orderData

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    The issue here relates to what the column is trying to reference. You have set it up to read the parameters plain (etc) from the data source object, but there is no plain parameter at the row level - its an array of objects.

    You would need to use 0.plain to access the plain value in the first array, 1.plain in the second, etc. So the issue is basically that the data is not where you are currently telling it.

    There is no way to do what you are currently looking for with just strings - you would need to use columns.render as a function, accessing the column index from the meta parameter that is passed in. So yes, it is possible, but it needs a couple of lines more code.

    Allan

This discussion has been closed.