Kendo ui grid Режим Fiter: ряд - PullRequest
1 голос
/ 11 марта 2019

Я использую режим столбца фильтра: строка в моей сетке.Для моего числового столбца меню показано так:

enter image description here

Мне нужен фильтр в этом столбце в качестве фильтра, который используется в режиме меню

enter image description here

Вот часть моего кода

 schema: {
                        data: "results",
                        total: "total",
                        model: {
                        id: "accountingTransactionKey",
                        fields: {
                            accountingTransactionKey: { editable: false, nullable: false },
                            date: { editable: false, nullable: false },
                            organization: { editable: false, nullable: false },
                            accountDebit: { editable: false, nullable: true },
                            costArticleUsed: { editable: false, nullable: true },
                            accountCredit: { editable: false, nullable: true },
                            isIntraGroupPartnerOrganization: { editable: false, nullable: true, type: "number" },
                            currency: { editable: false, nullable: true },
                            sum: { editable: false, nullable: true, type: "number"},...
                   ...{
                            field: "sum",
                            title: "Сумма",
                            width: "150px",
                            //format: "{0:n2}",
                            locked: true,
                            filterable:
                            {
                                multi: true,
                                cell:
                                {
                                    operator: "eq",
                                    suggestionOperator: "eq",
                                    showOperators: true
                                }
                            },
                            template: function (dataItem) { return numberWithSpaces(dataItem.sum.toFixed(2)) },
                            footerTemplate: "<b>" +"#: numberWithSpaces(sum.toFixed(2)) #"+"</b>"
                        },

Есть разрешение для моего запроса?

Спасибо

1 Ответ

0 голосов
/ 12 марта 2019

Я попробовал следующий скрипт, и он дает мне фильтр диапазона, используя свойство extra .

<script>
                $(document).ready(function() {

                  var griddata = createRandomData(50);

                    $("#grid").kendoGrid({
                        dataSource: {
                            data: griddata,
                            schema: {
                                model: {
                                    fields: {
                                        City: { type: "string" },
                                        Title: { type: "string" },
                                        BirthDate: { type: "date" },
                                        Age: { type: "number" }
                                    }
                                }
                            },
                            pageSize: 15
                        },
                        height: 550,
                        scrollable: true,
                        filterable: {
                            extra: false,
                            operators: {
                                string: {
                                    startswith: "Starts with",
                                    eq: "Is equal to",
                                    neq: "Is not equal to"
                                }
                            }
                        },
                        pageable: true,
                        columns: [
                            {
                                title: "Name",
                                width: 160,
                                filterable: false,
                                template: "#=FirstName# #=LastName#"
                            },
                            {
                                field: "City",
                                width: 130,
                                filterable: false,
                            },
                            {
                                field: "Title",
                                filterable: false,
                            },
                            {
                                field: "BirthDate",
                                title: "Birth Date",
                                format: "{0:MM/dd/yyyy HH:mm tt}",
                                filterable: false,
                            },
                            {
                                field: "Age",
                                width: 100,
                                filterable:
                                {
                                  extra: true
                                }
                            }
                       ]
                    });
                });
            </script>

Если вы хотите создать настроенный фильтр диапазона .

columns: [
                    {
                         field: "Age",
                               filterable: {
                                    cell: { template: betweenAgeFilter }
                               }
                    }
        ]

function betweenAgeFilter(args) {
            var filterCell = args.element.parents(".k-filtercell");
            filterCell.empty();
            filterCell.html('<span style="justify-content:center;"> <span>From:</span><input id="startAge"/><span>To:</span><input id="endAge"/></span>');

            $("#startAge").kendoNumericTextBox({
                change: function (e) {
                    var startAge = e.sender.value();
                    var endAge = $("#endAge").data("kendoNumericTextBox").value();
                    var dataSource = $("#grid").data("kendoGrid").dataSource;

                    if (startAge & endAge) {
                        var filter = { logic: "and", filters: [] };
                        filter.filters.push({ field: "Age", operator: "gte", value: startAge });
                        filter.filters.push({ field: "Age", operator: "lte", value: endAge });
                        dataSource.filter(filter);
                    }
                }
            });
            $("#endAge").kendoNumericTextBox({
                change: function (e) {
                    var startAge = $("#startAge").data("kendoNumericTextBox").value();
                     var endAge = e.sender.value();
                     var dataSource = $("#grid").data("kendoGrid").dataSource;

                    if (startAge & endAge) {
                        var filter = { logic: "and", filters: [] };
                        filter.filters.push({ field: "Age", operator: "gte", value: startAge });
                        filter.filters.push({ field: "Age", operator: "lte", value: endAge });
                        dataSource.filter(filter);
                    }
                }
            });
        }
...