grid datasouce ajax update problem
Hi,
When I'm updating datasource of the grid, it substitutes as total number of documents equal to the number of received valuefor example: Count of documents = 70, controllers query takes 8 documents, and after changing datasource max docs count equals 8 and pagination shows 1 page instead of 9.
Controller returns:
return Json(new { result = data /*8 elemetnts which on the page*/, count = count /*total count = 70*/ });
script:
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
url: '@Url.Action("GetDocs", "Documents")',
data: filterObj,
type: 'post',
success: function (res) {
var parsedData = ej.parseJSON(res);
$("#BoxesListGrid").ejGrid("dataSource", parsedData.result);
$("#BoxesListGrid").ejWaitingPopup("hide");
}
});
How to bind total count of docs?
SIGN IN To post a reply.
3 Replies
VN
Vignesh Natarajan
Syncfusion Team
July 12, 2017 03:59 PM UTC
Hi John,
Thanks for contacting Syncfusion support. We have analyzed your query and we are able to reproduce the issue at our end.
We have prepared a sample based on the code you provided.
Sample: http://www.syncfusion.com/downloads/support/forum/131457/ze/SyncfusionMvcApplication20-653090417
While updating the dataSource, you have considered only the .result value. So that grid has only that much records when updating. If you want total records to be displayed you can return all the records when updating.
|
function complete(args) {
// var vinet = "VINET";
$.ajax({
url: '@Url.Action("GetDocs")',
type: "POST",
dataType: "json",
//contentType: 'application/json; charset=utf-8',
data: { value: 70, count: 8 },
success: function (data) {
var parsedData = data;
$("#Grid").ejGrid("dataSource", parsedData.result);
$("#Grid").ejWaitingPopup("hide");
}
}); |
Or else if you want to display current page records alone you can use URL adaptor of Data manager in which it will return count and total records simultaneously.
|
$("#Grid").ejGrid("dataSource", ej.DataManager({url:"UrlDataSource", adaptor: new ej.UrlAdaptor() }); |
ServerSide code:
|
|
In above code snippet Datasource represent current page records, where count represent the total record count
Please refer our online sample for your reference
Regards,
Vignesh Natarajan
JO
John
July 14, 2017 03:15 AM UTC
if I use datamanager, how to send json object as a param to controller?
SA
Saravanan Arunachalam
Syncfusion Team
July 14, 2017 01:33 PM UTC
Hi John,
We understood from your query, you need to send additional parameter to the controller and we have achieved this requirement by using query property of Grid control. In the query property, we have send additional parameter by using addParams method of ejQuery that can be refer from the below code example.
|
$(function () {
var dataManager = ej.DataManager({ url: "/Home/DataSource", adaptor: new ej.UrlAdaptor() });
$("#Grid").ejGrid({
dataSource: dataManager,
query: new ej.Query().addParams("value", 5 ).addParams("count",6),
. . .
});
});
[controller]
public ActionResult DataSource(Syncfusion.JavaScript.DataManager value, Test t)
{
. . .
}
public class Test
{
public string value { get; set; }
public int count { get; set; }
}
|
And we have created a sample that can be downloaded from the below link.
Regrards,
Saravanan A.
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
JO John
- Jul 11, 2017 05:04 AM UTC
- Jul 14, 2017 01:33 PM UTC