Created
May 31, 2016 03:55
-
-
Save ChinhP/9b4dc1df1b12637b99a420aa268ae32b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.