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

Check are there rusults from the server

JS:
var dm = ej.DataManager({
    url: "/Home/get", crossDomain: true,
    updateUrl: '/Home/update',
    adaptor: new ej.UrlAdaptor()
});


$("#Grid").ejGrid({
    dataSource: dm,
    allowScrolling: true,
    allowVirtualScrolling: true,
    filterSettings: {
        filterType: "menu"
    },
    pageSettings: { enableQueryString: true, pageSize: 10 },
    columns: [
        { field: "data", headerText: "Data", isPrimarykey: true },
        { field: "value", headerText: "Value" },
    ]

});
I want to check if there are results from the server and if there are create/show grid.
How can I check that ?

5 Replies

RS Renjith Singh Rajendran Syncfusion Team September 5, 2017 12:58 PM UTC

Hi Customer, 

We have analyzed your query. We have achieved your requirement by using DataManager “executeQuery” and the jQuery “done” method. The done function is called for each successful post. We have checked a condition for the data returned from server. If no data is returned, the Grid won’t be rendered. If the dataSource is not empty, Grid will be renedered. Please refer the sample below, 

<script type="text/javascript"> 
    $(function () { 
        var dataManager = ej.DataManager({ url: "UrlDataSource", adaptor: new ej.UrlAdaptor() }); 
        var query = ej.Query().take(3); 
        var execute = dataManager.executeQuery(query)  
                .done(function (e) { 
                    if (e.actual.result.length) {         
                        $("#Grid").ejGrid({ 
                            dataSource: e.actual.result, 
                            ... 
                        }); 
                    } 
                }); 
    }); 
</script> 

Please refer the documentation link below, 

We have also prepared a sample based on your requirement, which can be downloaded from the link below, 
Regards, 
Renjith Singh Rajendran. 



NO noName September 5, 2017 10:21 PM UTC

Hi, thanks. It works, but in this way I am loosing infinity scroll. How can I set it back with your example ? Infinity scroll works if I set:

dataSource: dataManager

, but I think this is second request.



RS Renjith Singh Rajendran Syncfusion Team September 6, 2017 01:04 PM UTC

Hi Customer, 

Query 1: I am loosing infinity scroll 
 
In our last update we have not included the allowVirtualScrollingproperty of Grid. This is the reason for infinity scroll not enabled. Please refer the sample below, 

<script type="text/javascript"> 
    $(function () { 
         ... 
         $("#Grid").ejGrid({ 
            ... 
           allowScrolling: true, 
            scrollSettings: { height: 200, allowVirtualScrolling: true }, 
            ... 
         }); 
         ... 
   }); 
</script> 

Please download the modified sample from the link below, 

And also in the code example provided by you, the allowVirtualScrolling was not provided in proper format. The allowVirtualScrolling must be inside the scrollSettings property of Grid. 

Query 2: Infinity scroll works if I set: dataSource: dataManager 
 
In the provided sample, we have bound the JSON Data to the Grid. If you need to load the data on demand while scrolling you can bind dataManager to the dataSource. Please refer the code below, 

<script type="text/javascript"> 
    $(function () { 
         var dataManager = ej.DataManager({ url: "Home/UrlDataSource", adaptor: new ej.UrlAdaptor() }); 
         ... 
         $("#Grid").ejGrid({ 
            dataSource: dataManager,             
            ... 
         }); 
         ... 
   }); 
</script> 

Regards, 
Renjith Singh Rajendran. 



NO noName September 6, 2017 02:51 PM UTC

 By infinity scroll I mean load the data on demand while scrolling. Now I understand that I need to use 2 requests.

Ok, thx. Everything works.



MS Mani Sankar Durai Syncfusion Team September 7, 2017 04:05 AM UTC

Hi Customer, 

We are happy to hear that your problem has been solved. 

Please let us know if you need further assistance. 

Regards, 
Manisankar Durai. 


Loader.
Up arrow icon