Skip to content

Instantly share code, notes, and snippets.

@ChinhP
Created May 31, 2016 03:55
Show Gist options
  • Save ChinhP/9b4dc1df1b12637b99a420aa268ae32b to your computer and use it in GitHub Desktop.
Save ChinhP/9b4dc1df1b12637b99a420aa268ae32b to your computer and use it in GitHub Desktop.
public class DataTableParameters
{
public List<DataTableColumn> Columns { get; set; }
public int Draw { get; set; }
public int Length { get; set; }
public List<DataOrder> Order { get; set; }
public Search Search { get; set; }
public int Start { get; set; }
}
public class Search
{
public bool Regex { get; set; }
public string Value { get; set; }
}
public class DataTableColumn
{
public int Data { get; set; }
public string Name { get; set; }
public bool Orderable { get; set; }
public bool Searchable { get; set; }
public Search Search { get; set; }
}
public class DataOrder
{
public int Column { get; set; }
public string Dir { get; set; }
}
public class ExampleController : Controller
{
public ActionResult Index()
{
return View()
}
[HttpPost]
public JsonResult GetData(DataTableParameters dataTableParameters)
{
// put a debug here to see the values
// do anything else to handel to posted data
return View();
}
}
$(function () {
// start testing post data to GetData Action Result
var mobileFilter = {
CompanyNAME2: "a",
mobiletypes: [1,2,3]
};
var data = { "draw": 1, "columns": [{ "data": 0, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 1, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 2, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 3, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 4, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 5, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 6, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 7, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false} }, { "data": 8, "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false}}], "order": [{ "column": 0, "dir": "asc"}], "start": 0, "length": 10, "search": { "value": "", "regex": false} }
console.log(JSON.stringify(data));
$.ajax('/Example/GetData', {
datatype: 'json',
contentType: 'application/json',
type: 'post',
data: JSON.stringify({ dataTableParameters:data }),
success: function (response) {
console.log(response);
}
});
// end example, if posted successful, can apply to datatables.net below
$('#dataList').dataTable(
{
"iDisplayLength": 100,
"sPaginationType": "full_numbers",
processing: true,
serverSide: true,
ajax: {
type: "POST",
contentType: "application/json",
url: '<%=Url.Action("GetData","Example") %>',
data: function (d) {
// note: d is created by datatable, the structure of d is the same with DataTableParameters model above
console.log(JSON.stringify(d));
return JSON.stringify(d);
}
}
});
// your table structure here
<table id ="dataList">
....
</table>
@kaldas
Copy link

kaldas commented Jun 8, 2016

Thanks!

@resnyanskiy
Copy link

Also I recommend to have a look at https://github.com/ALMMa/datatables.aspnet

@issam1975
Copy link

Also I recommend to have a look at https://github.com/ALMMa/datatables.aspnet

thanks .

@Mashood15
Copy link

thanks bro

@yegorandrosov
Copy link

👍

@cristoferrao
Copy link

cristoferrao commented Feb 23, 2021

Nice, this is what I wanted searching for 3 days hope it works cuz didn't even know what to search for

@carloswm85
Copy link

What about getting a .json file with language initialization from local folder? https://datatables.net/examples/i18n/options.html Let's say, at run time I get locally the language file, and render it to the bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment