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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problem with grid sorting on document ready

Thread ID:

Created:

Updated:

Platform:

Replies:

141739 Jan 1,2019 04:06 PM UTC Jan 2,2019 12:52 PM UTC ASP.NET MVC 1
loading
Tags: Grid
Edwin Kurniawan
Asked On January 1, 2019 04:06 PM UTC

Hi admin, I have problem with ejGrid.
When i perform sorting on document ready (javascript) with my sort settings from serverside (i have saved sort settings state into database and load it),
and then assign the grid's datasource with a data manager (url adaptor), the sort settings state got reset.

How to persist sort column state when assigning the data source (initially null because i want to load the data source after doing some work after page loaded)?

Attached code:
var dataManagerId = xxx; //same as EJ().DataManager's id set on razor page
var sortColList = {//loaded from serverside};

$(function () {
      _customerGrid = $('#myCustomerGrid').ejGrid('instance');
      _customerGrid.option('sortSettings', sortColList);
      _customerGrid.option({ dataSource: dataManagerId }); //after setting datasource,
sortSettings getting reset.
      //If i set datasource before i set the sortSettings, double ajax request will be sent (want to avoid this)
});


Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On January 2, 2019 12:52 PM UTC

Hi Edwin, 

Thanks for contacting Syncfusion Support. 

Query#1:- How to persist sort column state when assigning the data source (initially null because i want to load the data source after doing some work after page loaded)? 

We have checked your query and when we set sortSettings before the dataSource, while updating the dataSource we have empty the sort, filter columns in our source side because when we doesn’t have such columns it will throw script Error. Because of that your reported problem arise. To overcome this problem, we need to set the property after updating the dataSource.  

Query #2:- If i set datasource before i set the sortSettings, double ajax request will be sent (want to avoid this) 
 
When we set dataSource before setting the sortSettings,  it will  send post for two times which is the default behavior while on updating dataSource and also for sortSettings.  To overcome this problem we have pass the query for sorting the Grid along with ejDataManager and also need to update the model of the sortSettings as like below code example:- 

    var dataManger = ej.DataManager({ 
            url: "/Home/DataSource", 
            insertUrl: "/Home/Insert", 
            updateUrl: "/Home/Update", 
            removeUrl: "/Home/Delete", 
            adaptor: "UrlAdaptor" 
        }); 
         
 
        $(function () { 
             $("#Grid").ejGrid({ 
                 dataSource: [], 
                 
               .   .    .         
            }); 
        }); 
 
    </script> 
    <script type="text/javascript"> 
        function refreshData() { 
            var grid = $('#Grid').ejGrid('instance'); 
            grid.option({ 
                dataSource: dataManger, 
                query: ej.Query().sortBy("EmployeeID", ej.sortOrder.Descending, false) 
            }); 
           grid.model.sortSettings.sortedColumns.push({field: "EmployeeID", direction: "descending" }) 
       } 
        
     </script> 


Refer to the documentation Link:- 
Please get back to us if you need any futher details. 
Regards, 

Farveen sulthana T 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;