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

sort multi filter checkbox values

6 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sandy
Top achievements
Rank 1
Iron
Veteran
sandy asked on 14 Jan 2021, 11:39 AM

Hi ,
i want to sort values in multi checkbox filter dropdown.
here am attaching image and project code . pls find it.

 

https://drive.google.com/file/d/1BigmLzF_12b2sFzANGrGWCWaA5j4gcBT/view?usp=sharing


6 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 18 Jan 2021, 08:59 AM

Hello Sandy,

Thank you for sharing the project with me.

Since the Grid DataSource does not use server operations (.ServerOperation(false)) the approach demonstrated in the below forum post can be used:

Please try it and let me know if you have any questions

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
sandy
Top achievements
Rank 1
Iron
Veteran
answered on 18 Jan 2021, 11:01 AM

Hi Nikolay,

if i use FilterMenuInit then aggrigate functions are not working properly while applying filters in pageload.

0
Nikolay
Telerik team
answered on 20 Jan 2021, 09:37 AM

Hello Sandy,

I have replied to another forum thread of yours discussing the same topic:

Please let me know if this helps. In case I am missing something please share more details.

As a side note, I suggest we continue the communication in a single thread, eighter here or in the above-mentioned one. As per our terms of use, different threads shall be submitted only for different inquiries.

Regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
sandy
Top achievements
Rank 1
Iron
Veteran
answered on 20 Jan 2021, 11:29 AM

Hi Nikolay,

That given link solution is different to this thread. so anyway i opened another thread with complete details and attached project.

0
Nikolay
Telerik team
answered on 22 Jan 2021, 02:02 PM

Hello Sandy,

I have replied to another thread of yours duplicate tho this one. Let's keep the communication there:

Kind regards,
Nikolay
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
sandy
Top achievements
Rank 1
Iron
Veteran
answered on 07 Mar 2021, 02:02 PM

Hi Nikolay,

here is my solution to my question. here am posting bcs it will useful to anybody.

 

in filterMenuInit function first am retrieving checked values in multi checkbox container. after getting checked values am storing in some variable. after am sorting values in multi checkbox container. after sorting values then am doing check box checked activity using datasource filter method. below is my code.

 

function filterMenuInit(e) {
        var FilterdValues = getGridFilterValues();
        if (e.field === "ProjectName.ProjectName" || e.field === "Dept.DeptName" ) {
            var title;
            if (e.field === "ProjectName.ProjectName") {
                title = "Project Name";
            }
            else if (e.field === "Dept.DeptName") {
                title = "Dept CC";
            }
           

            var filterMultiCheck = this.thead.find("[data-title='" + title + "']").data("kendoFilterMultiCheck")
            filterMultiCheck.container.empty();
            filterMultiCheck.checkSource.sort({ field: e.field, dir: "asc" });

            filterMultiCheck.checkSource.data(filterMultiCheck.checkSource.view().toJSON());
            filterMultiCheck.createCheckBoxes();
            //applyMyFilters();
        }
        if (FilterdValues.length > 0) {
            var filters = FilterdValues.split(',');
            var firstField = filters[0];
            var secondField = "";
            var thirdField = "";
            var fourthField = "";
            var fifthField = "";
            if (firstField != null && firstField != "") {
                var dataSource = $("#Grid").data("kendoGrid").dataSource;
                var _fltMain = [];
                var _fltParent = { logic: "and", filters: [] };
                var _flt = { logic: "or", filters: [] };
                var _fltSecond = { logic: "or", filters: [] };
                var _fltThird = { logic: "or", filters: [] };
                var _fltFourth = { logic: "or", filters: [] };
                var _fltFifth = { logic: "or", filters: [] };
                var bool = false;
                for (var i = 0; i < filters.length; i++) {
                    var filtercount = filters.length - 1;
                    if ((i % 3) == 0 && i < filtercount) {
                        if (filters[i] == firstField) {
                            _flt.filters.push({ field: filters[i], operator: filters[i + 1], value: filters[i + 2] });
                        }
                        else {
                            if (bool == false) {
                                _fltParent.filters.push(_flt);
                                bool = true;
                            }
                            if (secondField == "") {
                                secondField = filters[i];
                            }
                            else if (thirdField == "") {
                                thirdField = filters[i];
                            }
                            else if (fourthField == "") {
                                fourthField = filters[i];
                            }
                            else if (fifthField == "") {
                                fifthField = filters[i];
                            }
                            if (secondField == filters[i]) {
                                _fltSecond.filters.push({ field: filters[i], operator: filters[i + 1], value: filters[i + 2] });
                                thirdField = "";
                                fourthField = "";
                                fifthField = "";
                            }
                            else if (thirdField == filters[i]) {
                                //_fltParent.filters.push(_fltsecond);
                                //thirdField = filters[i];
                                _fltThird.filters.push({ field: filters[i], operator: filters[i + 1], value: filters[i + 2] });
                                fourthField = "";
                                fifthField = "";
                            }
                            else if (fourthField == filters[i]) {
                                _fltFourth.filters.push({ field: filters[i], operator: filters[i + 1], value: filters[i + 2] });
                                fifthField = "";
                            }
                            else if (fifthField == filters[i]) {
                                _fltFifth.filters.push({ field: filters[i], operator: filters[i + 1], value: filters[i + 2] });
                            }
                            else {

                                _fltParent.filters.push({ field: filters[i], operator: filters[i + 1], value: filters[i + 2] });
                            }
                        }
                    }
                }
                if (_fltSecond.filters.length > 0) {
                    _fltParent.filters.push(_fltSecond);
                }
                if (_fltThird.filters.length > 0) {
                    _fltParent.filters.push(_fltThird);
                }
                if (_fltFourth.filters.length > 0) {
                    _fltParent.filters.push(_fltFourth);
                }
                if (_fltFifth.filters.length > 0) {
                    _fltParent.filters.push(_fltFifth);
                }
                if (_fltParent.filters.length > 0) {
                    _fltMain.push(_fltParent);
                }
                else {
                    _fltMain.push(_flt);
                }
                dataSource.filter(_fltMain);
            }
        }
    }

 

 

 

function getGridFilterValues() {
        var dataSource = $("#Grid").data("kendoGrid").dataSource;
        var filter = dataSource.filter();
        let FilterdValues = [];
        $.each(filter, function (i, filters1) {
            if (filters1 != "and" && filters1 != "or") {
                $.each(filters1, function (j, filters2) {
                    if (filters2.field != "" && filters2.logic != "and" && filters2.logic != "or") {
                        FilterdValues += [filters2.field, filters2.operator, filters2.value, ""];
                    }
                    else {
                        $.each(filters2, function (k, filters3) {
                            if (filters3 != "and" && filters3 != "or") {
                                $.each(filters3, function (l, filters4) {
                                    if (filters4.field != "" && filters4.logic != "and" && filters4.logic != "or") {
                                        FilterdValues += [filters4.field, filters4.operator, filters4.value, ""];
                                    }
                                    else {
                                        $.each(filters4, function (m, filters5) {
                                            if (filters5 != "or" && filters5.logic != "and") {
                                                for (x = 0; x < filters5.length; x++) {
                                                    if (filters5[x].field != "") {
                                                        FilterdValues += [filters5[x].field, filters5[x].operator, filters5[x].value, ""];
                                                    }
                                                }

                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
        return FilterdValues;
    }

Tags
Grid
Asked by
sandy
Top achievements
Rank 1
Iron
Veteran
Answers by
Nikolay
Telerik team
sandy
Top achievements
Rank 1
Iron
Veteran
Share this question
or