一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect

摘要:
因此,带有复选框和联想功能的多选下拉列表出现了。Ext.ux.form.SuperBoxSelect确实是一个很好的插件,作者也将其应用到了项目中。这是一张测试截图。用户选择后可以看到自己的选择,非常直观!插件下载地址:Liveexample:http://technomedia.co.uk/SuperBoxSelect/examples3.htmlDownload:http://www.extjs.com/forum/attachmen...7&d=1263783379Thread:http://extjs.com/forum/showthread.ph...654#post332654我认为这个示例非常清楚如何使用这个插件。作者还基本参考了主板ExtMaster中C#版本的ExtJs组件。Master˂!

       在B/S系统中,下拉列表(select/dropdownlist/combobox)的应用随处可见,为了增强用户体验,开发人员也常常会做一些带联想功能的下拉列表,

        特别是数据项比较多的时候,用户筛选起来就会很容易。

        如果考虑多选的场景,我想以下的实现方式很多时候是能够满足要求的:

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第1张

带复选框(checkbox)的下拉列表,应该是比较直观和方便了,也很符合用户的习惯.

但是如果数据项太多的时候。滚动条会很长,有两个不足:

1.用户查询自己想要的目标很困难;

2.用户如果需要选择的项很多(>10项),滚动条容易遮挡住,用户可能也不知道自己到底选了哪些。

于是带复选框且有联想功能的多选下拉列表闪亮登场了, Ext.ux.form.SuperBoxSelect

这款插件确实很好用,笔者也将其应用到了项目中

这里给出测试截图

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第2张

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第3张

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第4张

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第5张

用户选择之后可以看到自己所选,很直观吧!

插件下载地址:

Live example: http://technomedia.co.uk/SuperBoxSelect/examples3.html

Download: http://www.extjs.com/forum/attachmen...7&d=1263783379

Thread: http://extjs.com/forum/showthread.ph...654#post332654

怎么使用这个插件,我想示例中是很明了的,笔者也做了一个C#版的

ExtJs组件的基础引用都在母板中

ExtMaster.Master

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第6张一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第7张
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="ExtMaster.master.cs"
    Inherits="Lucky.Views.Shared.ExtMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../Scripts/ext-3.4.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/ext-3.4.0/adapter/ext/ext-base-debug.js" type="text/javascript"></script>
    <script src="../../Scripts/ext-3.4.0/adapter/ext/ext-base.js" type="text/javascript"></script>
    <script src="../../Scripts/ext-3.4.0/ext-all.js" type="text/javascript"></script>
    <script src="../../Scripts/Widget/CHelper.js" type="text/javascript"></script>

    <asp:ContentPlaceHolder ID="TitleContent" runat="server">
    </asp:ContentPlaceHolder>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>
View Code

Vew视图:

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第8张一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第9张
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ExtMaster.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    
    <link href="../../Scripts/SuperBoxSelect/superboxselect.css" rel="stylesheet" type="text/css" />

    <script src="../../Scripts/SuperBoxSelect/states.js" type="text/javascript"></script>
    <script src="../../Scripts/SuperBoxSelect/SuperBoxSelect.js" type="text/javascript"></script>

    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <style type="text/css">
    body {
        font:13px/1.3 arial,helvetica,clean,sans-serif;
        *font-size:small;
        *font:x-small;
        padding: 20px !important;
    }
    #page {
        width: 700px;
    }
    p {
        color: #333;
        margin-bottom: 7px;
        font-size: 14px;
    }
    form p {
        margin-top: 7px;
    }
    code {
        color: #000;
    }
    #intro p {
        color: #000;
        font-size: 15px;
        margin-bottom: 20px;
    }
    h1 {
        font-size: 1.6em;
        line-height: 2.0em;
        margin-bottom: 0.8em;
    }
    h2 {
        font-size: 1.2em;
        line-height: 1.6em;
        margin-bottom: 0.6em;
    }
    .exForm{
        padding: 20px 20px 20px 0px;
        font-size: 12px;
    }
    .x-tag {
        color: #693;
        background-image: url(tag_green.gif);
        background-repeat: no-repeat;
        background-position:  2px center;
        padding-left: 17px !important;
        *text-indent: 17px !important;
    }
    .x-flag{
        background-image: url(../../Scripts/ext-3.4.0/resources/images/default/s.gif);
        background-repeat: no-repeat;
        background-position:  2px center;
        text-indent: 17px !important;
    }
    body.ext-ie6 .x-flag .x-superboxselect-item-close {
        top: 4px;
        right: 2px;
    }

    .small {
        font-size: small;
    }
    
    #f2Form .x-superboxselect-item-focus {
        color: #fff;
    }
    
</style>
    <script language="javascript" type="text/javascript">

        var tempIdCounter = 0;
        Ext.BLANK_IMAGE_URL = 'http://static.technomedia.co.uk/libs/ext-3.2.0/resources/images/default/s.gif';

        Ext.onReady(function () {


            $("#btnToastWindow").click(function () {

                GetWindow();

            });
        })

    </script>
    <script language="javascript" type="text/javascript">

        /**
        * ajax同步请求
        *获取用例对象
        */
        function GetSuperSelectData() {

            var obj;
            var value;
            var strUrl = '../SuoperBoxSelect/GetSuperSocketStore';

            if (window.ActiveXObject)
                obj = new ActiveXObject('Microsoft.XMLHTTP');
            else if (window.XMLHttpRequest)
                obj = new XMLHttpRequest;

            obj.open('POST', strUrl, false);
            obj.setRequestHeader('Contnent-Type', 'application/', 'application/x-www-form-urlencoded');
            obj.send(null);
            var oResult = Ext.util.JSON.decode(obj.responseText);

            return oResult;
        }
    
    </script>
    <script language="javascript" type="text/javascript">

        /**
        * form
        */
        function GetForm() {

            var SelectData = GetSuperSelectData();

            //example 5
            var states3 = new Ext.data.SimpleStore({
                fields: ['abbr', 'state', 'nick', 'cls'],
                data: SelectData,
                sortInfo: { field: 'state', direction: 'ASC' }
            });

            var superSelect = new Ext.ux.form.SuperBoxSelect({
                allowBlank: false,
                msgTarget: 'title',
                id: 'selector5',
                xtype: 'superboxselect',
                fieldLabel: 'States',
                resizable: true,
                hiddenName: 'statesHidden[]',
                 300,
                store: states3,
                mode: 'local',
                displayField: 'state',
                displayFieldTpl: '{state} ({abbr})',
                valueField: 'abbr',
                navigateItemsWithTab: false,
                value: ['AL', 'AZ']
            });

            var form = new Ext.form.FormPanel({
                frame: true,
                //title: '表单标题',
                style: 'margin:10px',
                items: [superSelect]
            });

            return form;

};

    /**
    * window
    */
    function GetWindow() {

        var form = GetForm();

        var win = new Ext.Window({
            title: '窗口',
             476,
            height: 374,
            items: [form],
            resizable: true,
            modal: true,
            closable: true,
            maximizable: true,
            minimizable: true,
            buttons: [{
                text: '确定',
                handler: function () {

                    var strValue = Ext.getCmp('selector5').getValue();
                    Ext.Msg.alert("提示", strValue);
                    win.close();
                }
            }, {
                text: '取消',
                handler: function () {

                    Ext.Msg.alert('提示', '取消');
                    win.close();
                }
            }]
        });

        win.show();

    }
    
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Example 5</h2>
    <p>
        This example demonstrates using <code>applyTo</code> to apply the component to an
        existing dom element.</p>
    <input type="button" id="btnToastWindow" value="弹出窗口" />
</asp:Content>
View Code

Controller:

这里只是构造一些测试数据,可以根据真是场景从数据库去数据和组织数据,

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第10张一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第11张
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lucky.Models;

namespace Lucky.Controllers
{
    public class SuoperBoxSelectController : Controller
    {
        //
        // GET: /SuoperBoxSelect/

        public ActionResult Index()
        {
            return View();
        }

        #region 获取多选下拉列表数据源

        /// <summary>
        /// 获取多选下拉列表数据源
        /// </summary>
        /// <returns></returns>
        public JsonResult GetSuperSocketStore()
        {
            var lstDoubleSuperSelectData = new List<List<string>>();
            var lstSuperSelect = _GetSuperSocketStore();

            foreach(var oSuperSelect in lstSuperSelect)
            {
                var lstSuperSelectData = new List<string>();
                lstSuperSelectData.Add(oSuperSelect.abbr);
                lstSuperSelectData.Add(oSuperSelect.state);
                lstSuperSelectData.Add(oSuperSelect.nick);
                lstSuperSelectData.Add(oSuperSelect.cls);

                lstDoubleSuperSelectData.Add(lstSuperSelectData);
            }

            return Json(lstDoubleSuperSelectData,JsonRequestBehavior.AllowGet);
        }


        private List<CSuperSelect> _GetSuperSocketStore()
        {
            var lstSuperSelect = new List<CSuperSelect>();

            for (var iIndex = 0; iIndex < 10;iIndex++ )
            {
                var strAbbr = string.Format("{0}{1}","abbr",iIndex);
                var strState = string.Format("{0}{1}","state",iIndex);
                var strNick = string.Format("{0}{1}", "nick", iIndex);
                var strCls = string.Format("{0}{1}", "cls", iIndex);

                lstSuperSelect.Add(new CSuperSelect(strAbbr,strState,strNick,strCls));
            }

            return lstSuperSelect;
        }
        #endregion

    }
}
View Code

Model:

一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第12张一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect第13张
 public class CSuperSelect
    {
        public string abbr;
        public string state;
        public string nick;
        public string cls;

        public CSuperSelect(string abbr, string state, string nick, string cls)
        {
            this.abbr = abbr;
            this.state = state;
            this.nick = nick;
            this.cls = cls;
        }
    }
View Code

参考:

http://www.sencha.com/forum/showthread.php?69307-3.x-Ext.ux.form.SuperBoxSelect

http://www.iteye.com/topic/392975

http://setting.iteye.com/blog/340900

 

转载请注明出处:http://www.cnblogs.com/lucky_hu/admin/EditPosts.aspx?opt=1

免责声明:文章转载自《一款不错的多选下拉列表利器—— Ext.ux.form.SuperBoxSelect》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SurfaceView 透明和半透明Linux配置浮动IP实现WEB高可用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

VB 的字符串处理函数

一、InStr 返回 Variant (Long),指定一字符串在另一字符串中最先出现的位置。 语法 InStr([start, ]string1, string2[, compare]) start 可选参数。为数值表达式,设置每次搜索的起点。如果省略,将从第一个字符的位置开始。如果 start 包含 Null,将发生错误。如果指定了 compar...

C#winform解析marc显示在datagridview中以及marc卡片显示

结果显示:marc显示: 卡片显示: 程序一个类: public class MARC { #region 界面上要显示的元素 public string ztm = "";//正题名 public string ftm = "";//副题名 public string fcm = "";//分册(辑)名 public string fch = "";...

android 蓝牙通信编程讲解

以下是开发中的几个关键步骤: 1,首先开启蓝牙 2,搜索可用设备 3,创建蓝牙socket,获取输入输出流 4,读取和写入数据 5,断开连接关闭蓝牙 下面是一个demo 效果图: SearchDeviceActivity.java [java]view plaincopy package com.hello.project;      impo...

从未如此简单:10分钟带你逆袭Kafka!【转】

【51CTO.com原创稿件】Apache Kafka 是一个快速、可扩展的、高吞吐的、可容错的分布式“发布-订阅”消息系统, 使用 Scala 与 Java 语言编写,能够将消息从一个端点传递到另一个端点。 较之传统的消息中间件(例如 ActiveMQ、RabbitMQ),Kafka 具有高吞吐量、内置分区、支持消息副本和高容错的特性,非常适合大规模消息...

容器编排系统K8s之包管理器Helm基础使用(一)

前文我们了解了k8s上的hpa资源的使用,回顾请参考:https://www.cnblogs.com/qiuhom-1874/p/14293237.html;今天我们来聊一下k8s包管理器helm的相关话题; helm是什么? 如果我们把k8s的资源清单类比成centos上的rpm包,那么helm的作用就如同yum;简单讲helm就是类似yum这样的包管理...

浅谈JEECG多数据源的使用

首先,简单的介绍下什么是JEECG。JEECG(J2EECode Generation)是一款基于代码生成器的免费开源的快速开发平台,使用JEECG可以简单快速地开发出企业级的Web应用系统。JEECG提倡简单功能由代码生成器直接生成,复杂业务采用表单自定义,业务流程使用工作流来实现、扩展出任务接口,由开发者编写特殊业务逻辑。 下面我们重点讲解下JEECG...