Search code examples
c#asp.net-mvcjsondatatables

Model binding new Datatables 1.10 parameters


In Datatables 1.10 the ajax server side parameters changed from

public class DataTableParamModel
{ 
    public string sEcho{ get; set; }
    public string sSearch{ get; set; }
    public int iDisplayLength{ get; set; }
    public int iDisplayStart{ get; set; }
    public int iColumns{ get; set; }
    public int iSortingCols{ get; set; }
    public string sColumns{ get; set; }
}

to (API Here http://datatables.net/manual/server-side)

columns[i][data]    
columns[i][name]    
columns[i][orderable]
columns[i][search][regex]
columns[i][search][value]   
columns[i][searchable]  
...     
draw    
length  
order[i][column]    
order[i][dir]
... 
search[regex]
search[value]   
start

Some are easy to bind

public class DataTableParamModel
{ 
    public string draw { get; set; }
    public int length{ get; set; }
    public int start { get; set; }
}

But the new array format looks tricky.

What is the new appropriate model to map the new parameter format?


Solution

  • I changed my javascript to use the legacy ajax params option which uses the old parameters to send to the server. This is done through $.fn.dataTable.ext.legacy.ajax = true; so now my code becomes something like...

    $.fn.dataTable.ext.legacy.ajax = true;
    var datatable = $('#data-table').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "MyController/AjaxHandlerPaging",
        "pageLength": 25,
        "order": [[2, 'desc']],
        "columns": []
    });