Retrieve Data Table From Server Side Using Ajax Do Not Bind Data to table.... Only Shows Loading..
Retrieve Data Table From Server Side Using Ajax Do Not Bind Data to table.... Only Shows Loading..
reninsome
Posts: 10Questions: 3Answers: 1
$("#GV1").DataTable({
serverSide: true,
ajax: {
type: "POST",
url: '@Url.Action("GetData", "Transaction")',
data: { typ: 1 },
dataType: "json",
success: function (result) {
},
error: function ajaxError(result) {
}
}
,
columns: [{ title: "Sno", type: "Integer" },
{ title: "M", type: "String" },
{ title: "Ct", type: "String" },
{ title: "F", type: "Number" },
{ title: "CS", type: "Number" },
{ title: "Q", type: "Number" },
{ title: "R", type: "Number" },
{ title: "A", type: "Number" }
]
});
This discussion has been closed.
Answers
Can you put your question in the message body please? Even reading the title I don't actually know what your question is. Also, please link to a test case showing the issue, as per the forum rules.
Allan
Thanku @allan for your kind interest. Actually Problem is I get data object in variable result of Success of ajax. When i bind this to datatable it do not work. Only "Loading ...... " message appear in table body. Here is data format that i got from database in ajax call ...
[
{
"Sno":1,
"M" : "Ghus",
"Ct" : "Kiop",
"F" : 12.78,
"CS" : 10.78,
"Q" : 18,
"R" : 16.356,
"A" : 1235
},
{
"Sno":2,
"M" : "Liop",
"Ct" : "Tres",
"F" : 28,
"CS" : 10.78,
"Q" : 18,
"R" : 156,
"A" : 15
}
]
Is there Any other way to bind this data ????
You can't return just a flat array if you are using server-side processing. If you are using server-side processing, you must return the parameters as described in the documentation.
If you don't need server-side processing, remove the
serverSide
option and useajax.dataSrc
set to be an empty string to tell DataTables to expect a top level array.Allan
Can you please show me in a simple example how to use it and bind data to datatable ??
"json.total" returns as undefined.
Hello @allan
Suddenly my code started working don't know where was the problem
Here is code
```$("#GV1").DataTable({
serverSide: true,
processing: true,
fixedHeader: true,
ajax: {
type: "POST",
url: '@Url.Action("GetData", "Transaction")',
data: { typ: 1 },
dataType: "json",
dataSrc: function (result) {
var json = jQuery.parseJSON(result);
return json;
}
}
,
columns: [{ data: 'Sno''},
{ data: 'M'},
{ data: 'Ct' },
{ data: 'F'},
{ data: 'CS'},
{ data: 'Q' },
{ data: 'R'},
{ data: 'A' },
]
,
dom: '<"html5buttons"B>lTfgitp',
buttons: [
{ extend: 'copy' },
{ extend: 'csv' },
{ extend: 'excel', title: 'ExampleFile' },
{ extend: 'pdf', title: 'ExampleFile' },
{
extend: 'print',
customize: function (win) {
$(win.document.body).addClass('white-bg');
$(win.document.body).css('font-size', '10px');
```
But there is an Issue in data table It Shows
> Showing 0 to 0 of 0 entries (filtered from NaN total entries)
That means Css is not working on binded dataset. What to do now ??
Problem Resolved
Wokrs when Serverside:false