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

Data Loading Finish,but don't Show

JS Code:
<script type="text/javascript">
        $(function () {
            $("#Grid").ejGrid({
                locale: "zh-CN",
                dataSource: ej.DataManager({
                    url: "/Roles/DataSource",              
                    insertUrl: "/Roles/Insert",                  
                    adaptor: 'UrlAdaptor'
                }),
                allowPaging: true,
                editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },
                toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] },
                columns: [
                { field: "Id", isPrimaryKey: true, headerText: '编号', allowEditing: false, textAlign: ej.TextAlign.Left },
                { field: "Name", headerText: "名称", editType: ej.Grid.EditingType.String, validationRules: { required: true, minlength: 1, maxlength:5 } },
                ]
            });
        });
    </script>
MVC 5 Code:
       public ActionResult DataSource(DataManager data)
        {
            var lst= Project_Web.Models.AspNetRolesService.Instance.GetAllModel(); // Get All Data
            return Json(new { result=lst,count=lst.Count },JsonRequestBehavior.AllowGet);
        }

        public ActionResult Insert(JObject value)
        {
            ParamInsert pi = new ParamInsert();
            pi.Insert(Project_Web.Models.AspNetRoles.TableName);
            pi.Column(Project_Web.Models.AspNetRoles.Column_Id, AspNetRolesService.Instance.GetNewCode()); //Get Max Code
            pi.Column(Project_Web.Models.AspNetRoles.Column_Name, DateTime.Now.ToString()); //Test
            AspNetRolesService.Instance.Insert(pi);  //Data Into Database
            var data = Project_Web.Models.AspNetRolesService.Instance.GetAllModel();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

First request Finish,Data show Right;
Add Data and Submitted,Data insert into  Database Success;Data Return to client Success,
Problem:
  1. why new Data not Show in Grid?Using Chrome developer tools  find Data is Exist,Invoke Insert Method after.
  2. why client request URL "/Roles/DataSource"  again  when Insert Method return all data to client.  
  3.Can  return EmptyResult with in  Insert Method? (in MVC)


1 Reply

GV Gowthami V Syncfusion Team April 25, 2016 12:25 PM UTC

Hi guoxuefeng, 

Thanks for using Syncfusion products. 

Query 1: why new Data not Show in Grid? Using Chrome developer tools  find Data is Exist, Invoke Insert Method after. 
 
We have analyzed your issue and we are  unable to reproduce the issue.  
 
We have created a sample and the same can be downloaded from the following link, 
 
 
From your code example we found that you have used UrlAdapor. While using this adaptor It will work as OnDemand paging and return only current page data.  
 
But in your code example you have not handled paging operation in server side and returned all the data. We suspect that it may be the cause of the issue. So instead of returning all the data for every post,  return only the current page data using paging details passed in DataManager type parameter. 
 
Refer to the below code example, 
 
@(Html.EJ().Grid<OrderTable>("Grid") 
        .Datasource(ds => ds.URL("GetEmployeeData") 
                            .InsertURL("PerformInsert") 
                           
                            .Adaptor(AdaptorType.UrlAdaptor) 
                            ) 
            .AllowPaging() 
             
. . . . 
. . . . 
  ) 
 
public ActionResult GetEmployeeData(DataManager dm) 
        { 
 
            IEnumerable data = (from o in new NORTHWNDEntities1().Tables 
                                //Binding selected data instead of all data 
                                select new EmployeeTable 
                                { 
                                    EmployeeID = o.EmployeeID, 
                                    FirstName = o.FirstName, 
                                    LastName = o.LastName, 
                                    Title = o.Title 
                                }).OrderBy(o=> o.EmployeeID); 
 
            int count = data.AsQueryable().Count(); 
            DataOperations operation = new DataOperations(); 
            
            //Performing paging operations 
            data = operation.PerformSkip(data, dm.Skip); 
            data = operation.PerformTake(data, dm.Take); 
            
            return Json(new { result = data, count = count }, JsonRequestBehavior.AllowGet); 
 
        } 
 
 
Refer to the below link for more clarification about adaptors, 


Query 2: why client request URL "/Roles/DataSource"  again  when Insert Method return all data to client. 

When using “UrlAdaptor” , it will work with OnDemand paging concept like it will return only current page data. 
 
If we have performed Filtering, Sorting and Searching actions before performing CRUD operation then we need to fetch the current page data based on filter, sort actions since the data source collection is modified. 
 
So that only we have called the “DataSource” method after performing CRUD operation. 

Query 3: Can  return EmptyResult with in  Insert Method? (in MVC) 

Yes. We can return the EmptyResult with Insert method. 

Regards, 

Gowthami V. 


Loader.
Live Chat Icon For mobile
Up arrow icon