Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >自定义Kendo下拉列表多项选择以使用复选框

自定义Kendo下拉列表多项选择以使用复选框
EN

Stack Overflow用户
提问于 2014-08-09 12:42:22
回答 2查看 7.3K关注 0票数 3

我正在使用从Telerik论坛收集到的一些自定义代码来修改Kendo在多选择小部件中构建的奇数代码,而不是使用复选框。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//MultiSelect - A user extension of KendoUI DropDownList widget.
(function ($) {
    // shorten references to variables
    var kendo = window.kendo,
        ui = kendo.ui,
        DropDownList = ui.DropDownList,
        keys = kendo.keys,
        SELECT = "select",
        SELECTIONCHANGED = "selectionChanged",
        SELECTED = "k-state-selected",
        HIGHLIGHTED = "k-state-active",
        CHECKBOX = "custom-multiselect-check-item",
        SELECTALLITEM = "custom-multiselect-selectAll-item",
        MULTISELECTPOPUP = "custom-multiselect-popup",
        EMPTYSELECTION = "custom-multiselect-summary-empty";

    var lineTemplate = '<input type="checkbox" name="#= {1} #" value="#= {0} #" class="' + CHECKBOX + '" />' +
                    '<span data-value="#= {0} #">#= {1} #</span>';

    var MultiSelectBox = DropDownList.extend({
        init: function (element, options) {
            options.template = kendo.template(kendo.format(lineTemplate, options.dataValueField, options.dataTextField));
            // base call to widget initialization
            DropDownList.fn.init.call(this, element, options);
        },
        options: {
            name: "MultiSelectBox",
            index: -1,
            showSelectAll: null,
            preSummaryCount: 1,  // number of items to show before summarising
            emptySelectionLabel: '',  // what to show when no items are selected
            selectionChanged: null, // provide callback to invoke when selection has changed
        },
        events: [
            SELECTIONCHANGED
        ],
        refresh: function () {
            // base call
            DropDownList.fn.refresh.call(this);
            this._updateSummary();
            $(this.popup.element).addClass(MULTISELECTPOPUP);
        },
        current: function (candidate) {
            return this._current;
        },
        open: function () {
            this._removeSelectAllItem();
            this._addSelectAllItem();
            DropDownList.fn.open.call(this);
            //hook on to popup event because dropdown close does not
            //fire consistently when user clicks on some other elements
            //like a dataviz chart graphic
            this.popup.one('close', $.proxy(this._onPopupClosed, this));
        },
        _onPopupClosed: function () {
            this._removeSelectAllItem();
            this._current = null;
            //this._highlightCurrent();
            this._raiseSelectionChanged();
        },
        _raiseSelectionChanged: function () {
            var currentValue = this.value();
            var currentValues = $.map((currentValue.length > 0 ? currentValue.split(",") : []).sort(), function (item) { return item.toString(); });
            var oldValues = $.map((this._oldValue || []).sort(), function (item) { return item.toString(); });
            // store for next pass
            this._oldValue = $.map(currentValues, function (item) { return item.toString(); });
            var changedArgs = { newValue: currentValues, oldValue: oldValues };
            if (oldValues) {
                var hasChanged = ($(oldValues).not(currentValues).length == 0 && $(currentValues).not(oldValues).length == 0) !== true;
                if (hasChanged) {
                    //if (this.options.selectionChanged)
                    //    this.options.selectionChanged(changedArgs);
                    this.trigger(SELECTIONCHANGED, changedArgs);
                }
            }
            else if (currentValue.length > 0) {
                //if (this.options.selectionChanged)
                //    this.options.selectionChanged(changedArgs);
                this.trigger(SELECTIONCHANGED, changedArgs);
            }
        },
        _addSelectAllItem: function () {
            if (!this.options.showSelectAll) return;
            var firstListItem = this.ul.children('li:first');
            if (firstListItem.length > 0) {
                this.selectAllListItem = $('<li tabindex="-1" role="option" unselectable="on" class="k-item ' + SELECTALLITEM + '"></li>').insertBefore(firstListItem);
                // fake a data object to use for the template binding below
                var selectAllData = {};
                selectAllData[this.options.dataValueField] = '*';
                selectAllData[this.options.dataTextField] = 'All';
                this.selectAllListItem.html(this.options.template(selectAllData));
                this._updateSelectAllItem();
                this._makeUnselectable(); // required for IE8
            }
        },
        _removeSelectAllItem: function () {
            if (this.selectAllListItem) {
                this.selectAllListItem.remove();
            }
            this.selectAllListItem = null;
        },
        _focus: function (li) {
            if (this.popup.visible() && li && this.trigger(SELECT, { item: li })) {
                this.close();
                return;
            }
            this.select(li);
        },
        //_highlightCurrent: function () {

        //    $('li', this.ul).removeClass(HIGHLIGHTED);
        //    $(this._current).addClass(HIGHLIGHTED);
        //},
        _keydown: function (e) {
            // currently ignore Home and End keys
            // can be added later
            if (e.keyCode == kendo.keys.HOME ||
                e.keyCode == kendo.keys.END) {
                e.preventDefault();
                return;
            }
            DropDownList.fn._keydown.call(this, e);
        },
        _keypress: function(e) {
            // disable existing function
        },
        _move: function (e) {
            var that = this,
                key = e.keyCode,
                ul = that.ul[0],
                down = key === keys.DOWN,
                pressed;
            if (key === keys.UP || down) {
                if (down) {
                    if (!that.popup.visible()) {
                        that.toggle(down);
                    }
                    if (!that._current) {
                        that._current = ul.firstChild;
                    } else {
                        that._current = ($(that._current)[0].nextSibling || that._current);
                    }
                } else {
                    //up
                    // only if anything is highlighted
                    if (that._current) {
                        that._current = ($(that._current)[0].previousSibling || ul.firstChild);
                    }
                }
                if (that._current) {
                    that._scroll(that._current);
                }
                that._highlightCurrent();
                e.preventDefault();
                pressed = true;
            } else {
                pressed = DropDownList.fn._move.call(this, e);
            }
            return pressed;
        },
        selectAll: function () {
            var unselectedItems = this._getUnselectedListItems();
            this._selectItems(unselectedItems);
            // todo: raise custom event
        },
        unselectAll: function () {
            var selectedItems = this._getSelectedListItems();
            this._selectItems(selectedItems);  // will invert the selection
            // todo: raise custom event
        },
        _selectItems: function (listItems) {
            var that = this;
            $.each(listItems, function (i, item) {
                var idx = ui.List.inArray(item, that.ul[0]);
                that.select(idx);  // select OR unselect
            });
        },
        _selectItem: function () {
            // method override to prevent default selection of first item, done by normal dropdown
            var that = this,
                options = that.options,
                useOptionIndex,
                value;
            useOptionIndex = that._isSelect && !that._initial && !options.value && options.index && !that._bound;
            if (!useOptionIndex) {
                value = that._selectedValue || options.value || that._accessor();
            }
            if (value) {
                that.value(value);
            } else if (that._bound === undefined) {
                that.select(options.index);
            }
        },
        _select: function (li) {
            var that = this,
                value,
                text,
                idx;
            li = that._get(li);
            if (li && li[0]) {
                idx = ui.List.inArray(li[0], that.ul[0]);
                if (idx > -1) {
                    if (li.hasClass(SELECTED)) {
                        li.removeClass(SELECTED);
                        that._uncheckItem(li);
                        if (this.selectAllListItem && li[0] === this.selectAllListItem[0]) {
                            this.unselectAll();
                        }
                    } else {
                        li.addClass(SELECTED);
                        that._checkItem(li);
                        if (this.selectAllListItem && li[0] === this.selectAllListItem[0]) {
                            this.selectAll();
                        }
                    }
                    if (this._open) {
                        that._current(li);
                        that._highlightCurrent();
                    }
                    var selecteditems = this._getSelectedListItems();
                    value = [];
                    text = [];
                    $.each(selecteditems, function (indx, item) {
                        var obj = $(item).children("span").first();
                        value.push(obj.attr("data-value"));
                        text.push(obj.text());
                    });
                    that._updateSummary(text);
                    that._updateSelectAllItem();
                    that._accessor(value, idx);
                    // todo: raise change event (add support for selectedIndex) if required
                }
            }

        },
        _getAllValueListItems: function () {
            if (this.selectAllListItem) {
                return this.ul.children("li").not(this.selectAllListItem[0]);
            } else {
                return this.ul.children("li");
            }
        },
        _getSelectedListItems: function () {
            return this._getAllValueListItems().filter("." + SELECTED);
        },
        _getUnselectedListItems: function () {
            return this._getAllValueListItems().filter(":not(." + SELECTED + ")");
        },
        _getSelectedItemsText: function () {
            var text = [];
            var selecteditems = this._getSelectedListItems();
            $.each(selecteditems, function (indx, item) {
                var obj = $(item).children("span").first();
                text.push(obj.text());
            });
            return text;
        },
        _updateSelectAllItem: function () {
            if (!this.selectAllListItem) return;
            // are all items selected?
            if (this._getAllValueListItems().length == this._getSelectedListItems().length) {
                this._checkItem(this.selectAllListItem);
                this.selectAllListItem.addClass(SELECTED);
            }
            else {
                this._uncheckItem(this.selectAllListItem);
                this.selectAllListItem.removeClass(SELECTED);
            }
        },
        _updateSummary: function (itemsText) {
            if (!itemsText) {
                itemsText = this._getSelectedItemsText();
            }
            if (itemsText.length == 0) {
                this._inputWrapper.addClass(EMPTYSELECTION);
                this.text(this.options.emptySelectionLabel);
                return;
            } else {
                this._inputWrapper.removeClass(EMPTYSELECTION);
            }

            if (itemsText.length <= this.options.preSummaryCount) {
                this._textAccessor(itemsText.join(", "));
            }
            else {
                this._textAccessor(itemsText.length + ' selected');
            }
        },
        _checkItem: function (itemContainer) {
            if (!itemContainer) return;
            itemContainer.children("input").prop("checked", true);
        },
        _uncheckItem: function (itemContainer) {
            if (!itemContainer) return;
            itemContainer.children("input").removeAttr("checked");
        },
        _isItemChecked: function (itemContainer) {
            return itemContainer.children("input:checked").length > 0;
        },
        value: function (value) {
            var that = this,
                idx,
                valuesList = [];
            if (value !== undefined) {
                if (!$.isArray(value)) {
                    valuesList.push(value);
                    this._oldValue = valuesList; // to allow for selectionChanged event
                }
                else {
                    valuesList = value;
                    this._oldValue = value; // to allow for selectionChanged event
                }
                // clear all selections first
                $(that.ul[0]).children("li").removeClass(SELECTED);
                $("input", that.ul[0]).removeAttr("checked");
                $.each(valuesList, function (indx, item) {
                    var hasValue;
                    if (item !== null) {
                        item = item.toString();
                    }
                    that._selectedValue = item;
                    hasValue = value || (that.options.optionLabel && !that.element[0].disabled && value === "");
                    if (hasValue && that._fetchItems(value)) {
                        return;
                    }
                    idx = that._index(item);
                    if (idx > -1) {
                        that.select(idx);
                    }
                });
                that._updateSummary();
            }
            else {
                var selecteditems = this._getSelectedListItems();
                return $.map(selecteditems, function(item) {
                    var obj = $(item).children("span").first();
                    return obj.attr("data-value");
                }).join();
            }
        },

    });
    ui.plugin(MultiSelectBox);
})(jQuery);

下面的代码将小部件添加到我的Kendo列数组中:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/****************************************************************
     * Set up the columns.
     ***************************************************************/
    var columns =  [
        {
            field: 'status',
            title: 'Status',
            width: 80,
            filterable: {
                extra: false, // Don't allow secondary filters.
                operators: {
                    // Sets up filter operators for "string" type columns.
                    string: {
                        // Allow 'equals'.
                        eq: "Equals"
                    }
                },
                ui: function(element) {
                    element.removeAttr("data-bind");
                    element.kendoMultiSelectBox({
                        dataSource: reasonCodes,
                        dataTextField: 'text',
                        dataValueField: 'value',
                        showSelectAll: false,
                        autoBind: false,
                        emptySelectionLabel: "--Select Value(s)--",
                        selectionChanged: function() {
                            applyStatusFilter(this.value());
                        }
                    });
                }
            },
            template: function(dataItem) {
                return dataItem.statusDesc;
            }
        }
    ];

下面是我的问题:下拉筛选器仍然显示用于选择"is等于“的Kendo”逻辑“框,这是我不想要的。我不知道如何在不影响列标题中的所有其他过滤器的情况下隐藏这个框,因为Kendo没有在它们上添加ID。

此外,当用户单击“--选择值”--“--”块时,过滤器和Cancel按钮会被下拉列表所阻塞,这意味着他们必须单击他们的选择,然后单击下拉菜单上方的按钮来关闭它,从而使按钮再次可见。

最好的情况是,我只想隐藏逻辑框,只针对此列,并将提交按钮移至下拉框的上方,以便在打开时它们是可见的。我仍然是一个非常绿色的javascripter,更不用说使用像Kendo这样的库,在那里做了那么多“自动魔术”,所以我一直在挣扎。

任何帮助都将不胜感激!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-27 06:26:08

实际上,我最终关闭了本专栏的筛选,使用headerTemplate选项向输入标记添加了一个ID,并添加了一个带有JQuery的multiSelectBox:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
var statusDropdown = $('#statusMultiSelect');
statusDropdown.kendoMultiSelectBox({
    dataTextField: 'text',
    dataValueField: 'value',
    dataSource: [{"value":"AC","text":"Active"},{"value":"OH","text":"On Hold"},{"value":"CL","text":"Closed"}],
    showSelectAll: false,
    emptySelectionLabel: "Status",
    selectionChanged: function() {
        applyStatusFilter(this.value());
    }
}); 

当在下拉列表中进行选择时,我只需根据下拉值手动操作kendo网格过滤器。

票数 0
EN

Stack Overflow用户

发布于 2016-04-13 12:53:18

由于未定义函数_fetchItems、_index和select,您的代码无法工作。这三个被称为value: function (value)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25222864

复制
相关文章
访问网站提示重定向的次数过多
【客户架构】域名解析到clb的vip上,并且在clb控制台上配置了http重定向https
张晗
2021/02/27
8.8K0
【Pikachu】URL重定向(不安全的URL跳转)
URL重定向(不安全的URL跳转) http://lzctf.thecat.top/vul/urlredirect/urlredirect.php?url=i lzctf.thecat.top/vul
菜菜有点菜
2022/03/17
2K0
【Pikachu】URL重定向(不安全的URL跳转)
Apache之Rewrite和RewriteRule规则梳理以及http强转https的配置总结(完整版)
一. 简单实例介绍 一般来说,apache配置好http和https后,如果想要做http强转到https,需要设置url重定向规则,大致需要下面几个步骤即可完成配置:
洗尽了浮华
2018/09/28
31.7K0
Apache URL重定向
Apached的重写功能,即是mod_rewrite模块功能,它是apache的一个模块。它的功能非常强大,可以操作URL中的所有部分。通过改写url,给用户提供一个简介大方的url,当用户访问时可以通过mod_rewrite模块功能转换为真正的资源路径。通过mod_rewrite能实现的功能还有很多,例如隐藏真实地址、实现URL跳转、域名跳转、防盗链、限制访问资源类型等等。
星哥玩云
2022/09/15
5.5K0
kvm timer导致exit过多的解决办法
惠伟:linux time和kvm time虚拟化综述​zhuanlan.zhihu.com
惠伟
2021/06/28
1.8K0
kvm timer导致exit过多的解决办法
timer简单理解就是cpu给硬件定时器写一个超时时间,超时时间到了后,硬件定时器超时后发送中断打断cpu。在虚拟化环境中,硬件定时器不存在,是kvm模拟出来的,guest给硬件定时器写超时时间就会导致guest exit出来,kvm进行模拟,kvm模拟时可以利用软件定时器也可以利用真正的硬件定时器,假如利用了真正的硬件定时器,kvm写完硬件定时器后重新enter guest,硬件定时器超时后发送中断打断cpu,cpu收到中断后从guest中exit出来,处理中断,然后把中断注入guest,模拟虚拟定时器的中断。这样guest就至少有两次exit。
惠伟
2022/04/28
8510
kvm timer导致exit过多的解决办法
URL重定向漏洞易受攻击的参数
/{payload} ?next={payload} ?url={payload} ?target={payload} ?rurl={payload} ?dest={payload} ?d
Khan安全团队
2022/05/17
1.4K0
URL重定向漏洞易受攻击的参数
让你的iPhone应用的URL更加友好易记
在你的应用程序上线后,经常要做对外推广的工作,经常会把你的应用程序的url贴在各处。 默认的iTunes链接的样子如下:
EltonZheng
2021/01/26
3580
http response code 301 和 302,你懂吗
一.官方说法 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redirect: 301 代表永久性转移(Permanently Moved)。 302 redirect: 302 代表暂时性转移(Temporarily Moved )。 这是很官方的说法,那么它们的区别到底是什么呢?
后端技术探索
2018/08/09
2.7K0
http response code 301 和 302,你懂吗
一.官方说法 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redirect: 301 代表永久性转移(Permanently Moved)。 302 redirect: 302 代表暂时性转移(Temporarily Moved )。 这是很官方的说法,那么它们的区别到底是什么呢?
后端技术探索
2018/08/09
1.1K0
go :gin URL重定向
本文介绍gin 框架下,URL重定向问题http重定向r.GET("/test", func(c *gin.Context) { c.Redirect(http.StatusMovedPermanently, "http://www.qq.com/")})完整测试代码package mainimport ( "net/http" "github.com/gin-gonic/gin")func main() { r := gin.Default() // Serves unico
IT工作者
2022/07/22
1.8K0
漏洞挖掘 - Url重定向
URL重定向的定义是指把一个目录或文件的访问请求转发到另一个目录或文件上,当用户发出相应的访问请求的时候,网页能跳转到指定的位置。
Khan安全团队
2021/08/26
4.3K0
漏洞挖掘 - Url重定向
Apache中 RewriteRule 规则参数介绍
大家好,又见面了,我是你们的朋友全栈君。Apache中 RewriteRule 规则参数介绍
全栈程序员站长
2022/08/27
12K0
使用FastAPI进行URL重定向
第一种方法,是直接返回一个RedirectResponse对象,默认的HTTP码是307:
SeanCheney
2023/01/10
5.6K0
使用FastAPI进行URL重定向
centos7-httpd服务器
Apache HTTP Server是Apache软件基金会的一个开源的网页服务器,可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是目前最流行的Web服务器端软件之一。
yuezhimi
2020/09/30
9040
WordPress登录后台重定向次数过多的解决办法
wordpress是目前全球最流行的cms内容管理系统之一。而目前chrome谷歌浏览器等主流浏览器都已经强制推广https链接,如果站点没有配置https访问,那么谷歌浏览器会在地址栏标注“不安全”。但是,如果你新安装的一个wordpress站点配置https后,再登录wordpress后台,却无法访问后台了。页面提示:将您重定向的次数过多,怎么办呢?
皇上得了花柳病
2020/07/08
7.3K0
EasyGBS平台对页面过多导致加载困难的问题优化
EasyGBS国标视频云服务平台不仅支持无缝、完整接入内网或者公网的国标设备,在输出上,实现全平台、全终端输出。平台可将GB/T28181设备/平台推送的PS流转成ES流,并提供RTSP、RTMP、FLV、HLS、WebRTC等多种格式视频流的分发服务,实现Web浏览器、手机浏览器、微信端、PC客户端等各终端无插件播放。
TSINGSEE青犀视频
2022/07/13
2770
Apache URL重定向配置专题
Rewrite url重定向就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范。平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等。
江中散人_Jun
2022/03/08
1.9K0
python 重定向获取真实url
楼主在做公司项目的时候遇到url重定向的问题,因此上网简单查找,作出如下结果 由于使用的是语言是python所以以下是python的简单解决方案 http_headers = { 'Accept': '*/*','Connection': 'keep-alive', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safar
py3study
2020/01/07
2.4K0
点击加载更多

相似问题

三元组中的三元组

23

连接三元组中的多个表

01

将元组元素组合到列表中

12

将OpenIE三元组转换为N-三元组(NT)

10

生日登记表三元组

11
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文