0

inside mvc controller I'm receiving MyTable as parameter

public JsonResult GetListOfData(JobTable result)
{
   var query = ... get data ..
   IQueryable<MyData> resData;
   resData.recordsFiltered = query.Skip(result.start).Take(50).AsQueryable();
   resData.recordsTotal = query.Count(); 
   ... 
   return Json(resData, JsonRequestBehavior.AllowGet);         
}

Inside view I have js code which initialize jquery data table

function drawTable() {
            var table = $('#myTable').dataTable({
                processing: true,
                serverSide: true,
                searching: false,
                lengthChange: false,
                displayLength: 25,
                order: [[5, 'desc']],
                ajax: {
                    url: '@Url.Action("GetListOfData", "Index")',
                    data: function (d) {
                        ...
                        d.status = $('#Status').val(),                        
                        d.dateFrom = $('#DateFrom').val(),
                        d.dateTo = $('#DateTo').val(),
                        ...                     
                    }
                },

                columns: [
                    { data: 'Id' },                    
                    { data: 'Status' },                                        
                    { data: 'CreatedDate' },
                    ...
                ],
                columnDefs: [
                    {
                        targets: [0, 3, 4],
                        orderable: false
                    },
                    {
                        render: function (data, type, row) {
                            return '<a href="@Url.Action("Details", "Index")/' + data + '"><i class="glyphicon glyphicon-folder-open"></i></a>'
                        },
                        title: '',
                        targets: 0
                    }
                ]
            });
        }

Question is: What I'm missing here to successfully implement server side pagination, what should I do to recognize clicked number inside view and receive that as part of MyTable parameter?

1 Answer 1

1

i just fixed it!! recordFiltered and recordsTotal should be of same length.

i was doing at serverside :

return Json(new
        {
            draw = param.draw,
            recordsTotal = allData.Count(),
            recordsFiltered = filteredData.Count(),
            data = result
        }, JsonRequestBehavior.AllowGet);

now i did:

return Json(new
        {
            draw = param.draw,
            recordsTotal = allData.Count(),
            recordsFiltered = allData.Count(),
            data = result
        }, JsonRequestBehavior.AllowGet);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.