This is a migrated thread and some comments may be shown as answers.
setting the whole sort of the grid from a single string
3 Answers 38 Views
This is a migrated thread and some comments may be shown as answers.
Luc
Top achievements
Rank 1
Luc asked on 01 Apr 2020, 11:17 AM

Hello,

 

When I call the following javascript API:

1.var grid = $('#Results').data('kendoGrid');
2.var ds = grid.dataSource;
3.var parameters = ds.transport.parameterMap({ sort: ds._sort, page: ds._page }, "read");

then I get an output like this:

{"sort":"Name-asc~Email-desc","page":2,"group":"","filter":""}

 

Is there any way (.net core or javascript) to pass the string "Name-asc~Email-desc" to the grid (or the datasource or any related objects) in order to apply the sorting ?

Thanks a lot!

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 06 Apr 2020, 08:11 AM

Hello, Luc,

The example that you have given appears to aim to format the parameters as one of the ajax mvc queries while the grid data source is most likely not this type of data source.

You can get the format you describe by using a different built-in transport parameter map. You need to include the script that contains it:

<script src=" https://kendo.cdn.telerik.com/2020.1.219/js/kendo.aspnetmvc.min.js"></script>

          var ajaxtransport = new kendo.data.transports["aspnetmvc-ajax"]({ prefix: "" });
          var params = ajaxtransport.parameterMap({
            page: grid.dataSource.page(),
            sort: grid.dataSource.sort(),
            filter: grid.dataSource.filter(),
            group:grid.dataSource.group()
          });

Here is a simple example: https://dojo.telerik.com/@bubblemaster/OfuVEXaV

Finally, note the use of the public data source methods sort(), filter(), group() and page() instead of the private properties:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods

Kind Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Luc
Top achievements
Rank 1
answered on 06 Apr 2020, 10:33 AM

Hello and thanks for the answer!

I think you may have misunderstood the question:

my grid has in fact an ajax type, and I am able to get/query this format into the string I showed in my first post. What I need to find out is how can I sort my grid by giving this string in this format? this is what does not seem to work for us. Getting this string is what we managed to do, now we are trying to use it to perform to full sorting in one call, as opposed to having to parse this string and manually build the list of sorting parameters with the member and the direction.

0
Alex Hajigeorgieva
Telerik team
answered on 09 Apr 2020, 07:56 AM

Hi, Luc,

The parameterMap of the Ajax() transport is designed to convert the inner request options in such way so they are intercepted on the server by the DataSourceRequest attribute and class.

A request with the query parameterized as pictured below to a controller action will be automatically deserialized giving you the components of the query - Filter, Sort, Group, Page, PageSize etc. and the extension method can be used to perform all the operations at once. In other words, there is no need for this to be done programmatically as it is already available when the expected parameters are as follows:

public ActionResult Customers_Read([DataSourceRequest]DataSourceRequest request)
{
        DataSourceResult result = customers.ToDataSourceResult(request);
        // result holds the paged, sorted, grouped and filtered collection able to bind to aspnet-ajax transport
        return Json(result);
}

If you wanted to perform the same query on the client and issue one request that has these components, you can use the query() method of the data source - pass the grid.dataSource sort(), filter(), group(), etc. at once:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/query

someWidget.dataSource.query({
 page: grid.dataSource.page(),
 sort: grid.dataSource.sort(),
 filter: grid.dataSource.filter(),
 group:grid.dataSource.group()
});

In case this is not the answer you were hoping for, could you explain the workflow in the project step by step and the desired end result so I can provide you with a more suitable suggestion.

Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Luc
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Luc
Top achievements
Rank 1
Share this question
or