Paginate records in server side procesing
Paginate records in server side procesing
alderhernandez
Posts: 33Questions: 11Answers: 1
hi. i am using server-side procesing in my proyect MVC5. im showing 10 record in 1 page.
but i want show 50 records (5 pages with 10 records each). the buttons next and previous are disable and i dont know why.
what i doing wrong???
here is mi code
$('#tblArticulos').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "LoadArticulos",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "NArticulo", "name": "NArticulo", "autoWidth": true },
{ "data": "CodigoDeBarras", "name": "CodigoDeBarras", "autoWidth": true },
{ "data": "Descripcion", "name": "Descripcion", "autoWidth": true },
{ "data": "descF", "name": "descF", "autoWidth": true },
{ "data": "UM", "name": "UND. MEDIDA", "autoWidth": true },
{ "data": "PrecioVenta", "name": "PrecioVenta", "autoWidth": true },
{ "data": "CostoPromedio", "name": "CostoPromedio", "autoWidth": true },
{ "data": "EsLote", "name": "EsLote", "autoWidth": true }
]
});
and here is mi controller
var draw = Request.Form.GetValues("draw").FirstOrDefault();
var start = Request.Form.GetValues("start").FirstOrDefault();
var length = Request.Form.GetValues("length").FirstOrDefault();
var sortColumn = Request.Form.GetValues("Columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
var sortColumDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
var search = Request.Form.GetValues("search[value]").FirstOrDefault();
int pageSize = length != null ? Convert.ToInt32(length) : 0;
int skip = start != null ? Convert.ToInt32(start) : 0;
int totalRecords = 0;
/*here go my LINQ query*/
////return the result
return Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet);
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Most likely the
recordsTotal
andrecordsFiltered
parameters are not set to 50.I would note that server-side processing with only 50 records is just going to introduce latency into your application. Only when you are into the tens of thousands of records is it worth thinking about normally.
Allan
im shure that are set to 50, beacouse im set the values manually sometimes
the page are show 50 record in 5 page each
I'm completely confused. Can you link to a test case showing the issue please?
The image appears to show that there are 50 records and the pagination control is shown correctly. If it doesn't change page when clicked then the server-side script isn't taking the
page
parameter into account.Allan
really sorry allan
in this image i take 25 record from mi database, the table lenght is 10. but the tables show me 25 record in 3 pages i want 10 records in each page
first page->> 1-10
second page->>11-20
third page->>21-25
I need to do it with 25 register for later test with 17000
I can not. the policies of my company do not leave me. im desperate
hI, i fix it changing this line
but now the records filter dont work
show me "Showing 0 to 0 of 0 entries" always
@allan now works all.
the recordsFiltered needs know the total of record (17730 in my case) for that i do a count of my table
recordsTotal = db.myTable.Count();
and i pass in the json
and thats all. working in mvc5.
Good to hear it is working now. Thanks for the update.
Allan