This is a migrated thread and some comments may be shown as answers.

[Solved] DataSource parameterMap example

3 Answers 1007 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jadranko Dragoje
Top achievements
Rank 1
Jadranko Dragoje asked on 08 Dec 2011, 01:48 PM
Hello.
I need to convert kendo sorting and filtering parameters like this:

Instead of this parameters: 
sort[0][field] = title
sort[0][dir] = asc
sort[1][field] = description
sort[1][dir] = asc

I need single orderBy parameter like this:
orderBy = title asc, description desc

Can you show me how can I get this?

$(document).ready(function () {
           convertSort = function (sort) {
               //TODO: Convert sorting parameters.
           };
 
           $("#grid").kendoGrid({
               dataSource: {
                   type: "json",
                   transport: {
                       read: "Read",
                       parameterMap: function (options) {
                           return {
                               page: options.page,
                               pageSize: options.pageSize,
                               orderBy: convertSort(options.sort)
                           }
                       }
                   },
                   schema: {
                       data: "Items",
                       total: "Total"
                   },
                   pageSize: 5,
                   serverPaging: true,
                   serverFiltering: false,
                   serverGrouping: false,
                   serverSorting: true
               },
               pageable: true,
               filterable: false,
               groupable: false,
               sortable: {
                   mode: "multiple",
                   allowUnsort: true
               },
               columns: [
                   { field: "Name", title: "Naziv" },
                   { field: "Title", title: "Naslov" },
                   { field: "Description", title: "Opis" }
               ]
           });
       });


3 Answers, 1 is accepted

Sort by
0
Jadranko Dragoje
Top achievements
Rank 1
answered on 08 Dec 2011, 02:13 PM
OK, I think I got it:

convertSortingParameters = function (original) {
    if (original) {
        var converted, sortIndex;
        converted = "";
        for (sortIndex = 0; sortIndex < original.length; sortIndex += 1) {
            if (sortIndex > 0) { converted += ", " }
            converted += original[sortIndex].field + " " + original[sortIndex].dir;
        }
        return converted;
    }
};

Is there a cleaner solution?
0
Shannon
Top achievements
Rank 1
answered on 25 Jan 2015, 08:04 PM
Would be nice to hear if there is a better solution, or at least some docs on how to do this in each of the versions of KendoUI.  
0
Kiril Nikolov
Telerik team
answered on 28 Jan 2015, 03:40 PM

Hello Shannon,

As this is not a behavior that is support built-in you will need to convert the objects yourself. The proposed solution should give you the expected results, but if you stumble upon any issues, please do not hesitate to contact us.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Jadranko Dragoje
Top achievements
Rank 1
Answers by
Jadranko Dragoje
Top achievements
Rank 1
Shannon
Top achievements
Rank 1
Kiril Nikolov
Telerik team
Share this question
or