We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

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 value
for 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?

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. 
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: 
public ActionResult UrlDataSource(DataManager dm)        {            IEnumerable DataSource = OrderRepository.GetAllRecords();            DataOperations ds = new DataOperations();            List<string> str = new List<string>();            var count = DataSource.Cast<EditableOrder>().Count();            DataSource = ds.PerformSkip(DataSource, dm.Skip);            DataSource = ds.PerformTake(DataSource, dm.Take);            return Json(new { result = DataSource, count = count, aggregate = aggregate });        }
  
  
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. 


Loader.
Live Chat Icon For mobile
Up arrow icon