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

Custom grid filters

3 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 19 Apr 2013, 09:42 AM
$(document).ready(function () {
    $('.AdvancedSearch input:checkbox').change(function () {
        ApplyFilters();
    });
 
    ApplyFilters();
});
         
function updateFlagSearchFilters(field, operator, value) {
    var grid = $("#Grid");
    var newFilter = { field: field, operator: operator, value: value };
    var dataSource = grid.data("kendoGrid").dataSource;
    var filters = null;
    if (dataSource.filter() != null) {
        filters = dataSource.filter().filters;
    }
    if (filters == null) {
        filters = [newFilter];
    }
    else {
        var isNew = true;
        var index = 0;
        for (index = 0; index < filters.length; index++) {
            if (filters[index].field == field) {
                isNew = false;
                break;
            }
        }
        if (isNew && value != "" && value != "0" && value != "False") {
            filters.push(newFilter);
        }
        else if (!isNew){
            filters.splice(index, 1);
        }
    }
    dataSource.filter(filters);
};
 
function ApplyFilters() {
    var pt2Checked = $('#Pt2').is(':checked');
    if (pt2Checked) {
        updateFlagSearchFilters("Pt2", "eq", "true");
    }
    else {
        updateFlagSearchFilters("Pt2", "neq", "");
    }
};
Hey guys,

As you can see i tried to make a custom grid filter, but somehow i can't get the Splice for removing filters to work. Is anyone having the same issue? Adding a filter is no problem, but i'm using the column filters as well so i don't want to clear all filters for unchecking a checkbox.

I would really appreciate all help on this, thanks in advance!

Max

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 22 Apr 2013, 03:30 PM
Hi Max,

Your code looks OK. I am not sure sure where exactly the problem comes from. Can you please provide a small but runnable example together with step by step instructions how to reproduce the issue? In this way I would be able to examine your case in details, examine what is going wrong and provide you with a concrete recommendations.

Thank you in advance for the cooperation.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Max
Top achievements
Rank 1
answered on 23 Apr 2013, 11:51 AM
Hi Alexander,

Thanks for your reply, i'm not sure how to make a quick example code for this since i'm not using the javascript library but the other one. My code runs on an existing database and creating an example would take up too much time for this. Is there any other way that you know of to create custom flag filters? (checkboxes only filtering when checked?) The filters are based on existing fields, but are not visible columns in my grid.

Thanks again,

Max
0
Alexander Valchev
Telerik team
answered on 24 Apr 2013, 03:13 PM
Hi Max,

Could you please specify what do you mean by "I'm not using the javascript library but the other one"?

I do not believe that the problem is directly connected with the data that the Grid is bound to. Can you try to isolate the problem in a sample page that uses mock data?

The Grid does not provide opportunity for creating flag filters out of the box. Implementing such feature requires custom JavaScript implementation.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Max
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Max
Top achievements
Rank 1
Share this question
or