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

Custom filter using grouped DropDownList

2 Answers 598 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 2
Andrew asked on 13 Sep 2013, 04:05 PM

Hi,

I've set up a Kendo Grid, and am customising the filter interface to show all values in a DropDownList. Through the DropDownList DataSource object I'm grouping on the field to be displayed (thereby removing any duplicates).

This works fine and shows exactly those values which should show, however on selecting a value I get an error in the kendo.all.js change function at the following line:

sourceValue = sourceItem.get(field);

The error being "Object doesn't support property or method 'get'"

Is this a bug in Kendo, or am I doing something wrong?!

For reference, the DropDownList is set up using the following code which is called from the filter UI function for each individual column (this applies to several columns). The filter function is there to filter the values based on all filters applied to the grid (i.e. so each filter only shows those values which are currently present in the grid according to applied filters):

function setFilter(url, element, field) {
    element.kendoDropDownList({
        dataSource: {
            transport: {
                read: {
                    url: url,
                    data: {
                        filter: function() {
     
                            var filters = $("#AccountsGrid").data("kendoGrid").dataSource.filter();       
                            var result = {};
 
                            if (filters) {
                                result.logic = filters.logic;
 
                                var filterArray = new Array();
 
                                for (var i = 0; i < filters.filters.length; i++) {
                                    filterArray.push({
                                        operator: filters.filters[i].operator,
                                        field: filters.filters[i].field,
                                        value: filters.filters[i].value
                                    });
                                }
 
                                result.filters = filterArray;
                            }
                            return JSON.stringify(result);
                        }
                    }
                }
            },
            group: {
                field: field
            },
            serverFiltering: true
        },
        dataValueField: "value",
        dataTextField: "value",
        optionLabel: "--Select Value--"
    });
}

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 17 Sep 2013, 08:48 AM
Hi Andrew,

At present the DropDownList widget does not support grouped dataSource which is why you receive the error. Actually the DropDownList items are not even supposed to render, in your case they do because both text and value field are set to display "value". Although that in your particular case the items are rendered by chance, the rest of the framework logic does not work.

My recommendation is to consider filtering the duplicated records on the server (for example a simple distinct in the SQL query should do the job). Alternatively you may trim the duplicated records on the client (parse function).

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Andrew
Top achievements
Rank 2
answered on 23 Sep 2013, 01:28 PM
Hi Alexander,

Thanks - I've filtered it using the schema.parse function, that works brilliantly. Admittedly, filtering it on the server would be better but sadly not possible due to the way the application is designed.

Kind regards,

Andrew
Tags
Grid
Asked by
Andrew
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Andrew
Top achievements
Rank 2
Share this question
or