How to get the parameters on MVC Controller send by ajax serverSide datatable 1.10
How to get the parameters on MVC Controller send by ajax serverSide datatable 1.10
Hi
I'm working on MVC 5, and I'm trying to get the parameters send by the ajax serverSide (DataTables 10), currently I'm using the following example:
public JsonResult AjaxHandler(jQueryDataTableParamModel param)
{
var dataResult = new List<string[]>() {
new string[] {"1", "Microsoft", "Redmond", "USA"},
new string[] {"2", "Google", "Mountain View", "USA"},
new string[] {"3", "Gowi", "Pancevo", "Serbia"}
};
return Json(new
{
draw = param.draw,
recordsTotal = dataResult.Count(),
recordsFiltered = dataResult.Count(),
data = dataResult
},
JsonRequestBehavior.AllowGet);
}
and my questions is about how to configure my jQueryDataTableParamModel class in order to get the parameters send by the DataTable.
public class jQueryDataTableParamModel
{
public int draw { get; set; }
public int start { get; set; }
public int length { get; set; }
public Dictionary<string, string> search { get; set; }
List<Dictionary<string, string>> order { get; set; }
List<Dictionary<string, string>> columns { get; set; }
}
Right now my example is working however I'm not getting the values for order and columns, just draw, start,length and search.
Can you help me to define the correct definition for order and columns in order to get the values send by the datatable.
I debug the request send to the controller and I get the following:
Request GET /Home/AjaxHandler?
draw=1&
columns[0][data]=0&
columns[0][name]=&
columns[0][searchable]=true&
columns[0][orderable]=true&
columns[0][search][value]=&
columns[0][search][regex]=false&
columns[1][data]=1&
columns[1][name]=&
columns[1][searchable]=true&
columns[1][orderable]=true&
columns[1][search][value]=&
columns[1][search][regex]=false&
columns[2][data]=2&
columns[2][name]=&
columns[2][searchable]=true&
columns[2][orderable]=true&
columns[2][search][value]=&
columns[2][search][regex]=false&
columns[3][data]=3&
columns[3][name]=&
columns[3][searchable]=true&
columns[3][orderable]=true&
columns[3][search][value]=&
columns[3][search][regex]=false&
order[0][column]=0&
order[0][dir]=asc&
start=0&
length=10&
search[value]=&
search[regex]=false&
I really appreciate your help about how to get the columns and order values...
Answers
same problem here...
Developin in Visual Strudio 2013 fw 4.5.1 and datatablesd 1.10.7.
I'm not able to get in request string params like "sEcho" or "sSearch"
any idea?
thank you all!
my datatables
$('#tabella').DataTable({
processing: true,
serverSide: true,
language: dataTables.it,
search: {
"caseInsensitive": true
},
pageLength: 10,
lengthChange: false,
columns: [
{
data: "Nome",
name: "Nome"
}, {
data: "Cognome",
name: "Cognome"
}]});
I am having the same issue here. The parameters being passed in, especially the search[value] parameter are not able to be processed by the server side language.
I did read some information about activating a legacy mode to get the pre version 1.10 parameters to be passed in.
...
$.fn.dataTable.ext.legacy.ajax = true;
...
I will try this one later and let you know, however, it would be nice to have parameters sent in that make more sense.
The search[value] parameter as processed by ColdFusion would assume that 'value' is a an integer index to an array position or a string key for a structure. However, 'value' is never declared on it's own, so there is no real way to know.
I found this elsewhere to process the search[value]
http://www.datatables.net/forums/discussion/22255/coldfusion-1-10-search-value-question
<cfset search_value = form['search[value]']>
Here is my solution
Here Is classes
And Usage