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

parameterMap fails when filter defined

1 Answer 521 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 2
Bill asked on 05 Dec 2014, 01:06 AM
I have a paramaterMap and a datasource filter defined as below and they almost work as needed but is failing to properly form the query string parameter for the filter on a read operation.  

When I remove the parameter map, it works fine and resolves the filter in the query string as &$filter=UserRoleId eq 3.  
With the parameterMap in place, it resolves as &filter[logic]=and&filter[filters][0][field]=UserRoleId&filter[filters][0][operator]=eq&filter[filters][0][value]=3. This becomes 4 junk parameters and while this doesn't throw any errors, my odata controller does not filter when params like this are passed.

How do I get the parameterMap to return a query param of "$filter:UserRoleId eq 3" instead of the 4 junk parameters described above?

                            parameterMap: function (data, operation) {
                                if (operation !== "read" && data) {
                                    data.UserRoleId = userRoleId;
                                    if (operation !== "destroy") {
                                        data.ConstraintValueId = $('#ddlConstraintValue').val();
                                        data.ConstraintValue = null;
                                    }
                                    return kendo.stringify(data);
                                }
                                else
                                    if (operation === "read" && data)
                                        return data;

                            }
                         .
                         .
                         .    
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true,
                        selectable: true,
                        filter: { field: "UserRoleId", operator: "eq", value: userRoleId },

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 08 Dec 2014, 02:20 PM
Hello Bill,

As you may know when using a odata type of the DataSource, a special predefined type of transport is used. This transport has a parameterMap which "knows" how to serialize the filter, sorting and paging information in OData compatible format. However, as you have defined your own parameterMap you have overridden the built-in one. Thus, you have to call the built-in parameterMap in order to serialize the parameters correctly.

parameterMap: function(options, operation) {
  if (operation == "read") {
    return kendo.data.transports["odata"].parameterMap(options);
  }
}


Regards,
Rosen
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
Bill
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or