extjscheckboxfield的簡單介紹

本文目錄一覽:

extjs CheckboxGroup默認選中問題

Ext.onReady(function() {

var port = new Ext.Viewport({

layout: ‘border’,

items: [chkEditDomain],

cls: “inner-viewport”,

listeners: {

render: function() {

// Ext.getCmp(“itemsid0”).setValue(“211”, true);

// Ext.getCmp(“itemsid0”).setValue(“212”, true);

// Ext.getCmp(“itemsid0”).setValue(“213”, true);

// Ext.getCmp(“itemsid0”).setValue(“214”, true);

}

}

});

});

var chkEditDomain = new Ext.form.CheckboxGroup({

xtype: ‘checkboxgroup’,

fieldLabel: ‘測試’,

name: ‘chkEditDomain’,

allowBlank: false,

id: ‘itemsid0’,

width: 200,

columns: 4,

items: [

{ boxLabel: ‘IND’, name: ‘IND’, id: ‘211’, inputValue: ‘5’, checked:true },

{ boxLabel: ‘CE’, name: ‘CE’, id: ‘212’, inputValue: ‘6’ ,checked:true},

{ boxLabel: ‘SC’, name: ‘SC’, id: ‘213’, inputValue: ‘8’ ,checked:true},

{ boxLabel: ‘FA’, name: ‘FA’, id: ‘214’, inputValue: ‘7’ ,checked:true}

]

});

這樣行嗎?

在ext中如何動態設置checkbox的checked屬性!

首先你要請確保每一個checkbox都有一個唯一的id,例如:

boxLabel : ‘新增’,

id:”add”,

anchor:”50%”,

name : ‘新增’

Ext.getCmp.setValue(true);設置為選中狀態

Ext.getCmp.setValue(false);設置為未選中狀態

Extjs怎麼實現下拉框多選

1、擴展js類庫,在項目中建立一個 js文件,命名為:xxx.js  其代碼為

if (‘function’ !== typeof RegExp.escape)   

{  

    RegExp.escape = function (s)   

    {  

        if (‘string’ !== typeof s)   

        {  

            return s;  

        }  

        return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, ‘\\$1’);  

    };  

}  

  

Ext.ns(‘Ext.form’);  

  

Ext.form.MultiSelect = Ext.extend(Ext.form.ComboBox,   

{  

    checkField: ‘checked’,  

    multi: true,  

    separator: ‘,’,  

    initComponent: function ()   

    {  

        if (!this.tpl)   

        {  

            this.tpl = ‘tpl for=”.”‘ + ‘div class=”x-combo-list-item”‘  

                    + ‘img src=”‘ + Ext.BLANK_IMAGE_URL + ‘” ‘  

                    + ‘class=”ux-MultiSelect-icon ux-MultiSelect-icon-‘  

                    + ‘{[values.’ + this.checkField + ‘?”checked”:”unchecked”‘  

                    + ‘]}”‘  

                    + ‘{[values.’ + this.displayField + ‘]}’  

                    + ‘/div’  

                    + ‘/tpl’;  

        }  

  

        Ext.form.MultiSelect.superclass.initComponent.apply(this, arguments);  

  

        this.on(  

        {  

            scope: this,  

            beforequery: this.onBeforeQuery,  

            blur: this.onRealBlur  

        });  

  

        this.onLoad = this.onLoad.createSequence(function ()   

        {  

            if (this.el)   

            {  

                var v = this.el.dom.value;  

                this.el.dom.value = ”;  

                this.el.dom.value = v;  

            }  

        });  

    },  

    initEvents: function ()   

    {  

        Ext.form.MultiSelect.superclass.initEvents.apply(this, arguments);  

        this.keyNav.tab = false;  

    },  

    beforeBlur: function ()   

    {  

    },  

    postBlur: function ()   

    {  

    },  

  

    clearValue: function ()   

    {  

        this.value = ”;  

        this.setRawValue(this.value);  

        this.store.clearFilter();  

        this.store.each(function (r)   

        {  

            r.set(this.checkField, false);  

        }, this);  

        if (this.hiddenField)   

        {  

            this.hiddenField.value = ”;  

        }  

        this.applyEmptyText();  

    },  

    getCheckedDisplay: function ()   

    {  

        var re = new RegExp(this.separator, “g”);  

        return this.getCheckedValue(this.displayField).replace(re, this.separator + ‘ ‘);  

    },  

    getCheckedValue: function (field)   

    {  

        field = field || this.valueField;  

        var c = [];  

        var snapshot = this.store.snapshot || this.store.data;  

        snapshot.each(function (r)   

        {  

            if (r.get(this.checkField))   

            {  

                c.push(r.get(field));  

            }  

        }, this);  

  

        return c.join(this.separator);  

    },  

    onBeforeQuery: function (qe)   

    {  

        qe.query = qe.query.replace(new RegExp(RegExp.escape(this.getCheckedDisplay()) + ‘[ ‘ + this.separator + ‘]*’), ”);  

    },  

    onRealBlur: function ()   

    {  

        this.list.hide();  

        var rv = this.getRawValue();  

        var rva = rv.split(new RegExp(RegExp.escape(this.separator) + ‘ *’));  

        var va = [];  

        var snapshot = this.store.snapshot || this.store.data;  

  

        Ext.each(rva, function (v)   

        {  

            snapshot.each(function (r)   

            {  

                if (v === r.get(this.displayField))   

                {  

                    va.push(r.get(this.valueField));  

                }  

            }, this);  

        }, this);  

        this.setValue(va.join(this.separator));  

        this.store.clearFilter();  

    },  

    onSelect: function (record, index)   

    {  

        if (this.fireEvent(‘beforeselect’, this, record, index) !== false)   

        {  

            record.set(this.checkField, !record.get(this.checkField));  

  

            if (this.store.isFiltered())   

            {  

                this.doQuery(this.allQuery);  

            }  

  

            if (this.multi)   

            {  

                if (record.get(“key”) == “—”  record.get(this.checkField))   

                {  

                    this.setValue(“—“);  

                }  

                else   

                {  

                    this.setValue(this.getCheckedValue());  

                }  

            }  

            else   

            {  

                this.clearValue();  

                this.value = record.get(this.valueField);  

                this.setRawValue(record.get(this.displayField));  

                this.list.hide();  

            }  

  

            this.fireEvent(‘select’, this, record, index);  

        }  

    },  

    setValue: function (v)   

    {  

        if (v)   

        {  

            v = ” + v;  

            if (this.valueField)   

            {  

                this.store.clearFilter();  

                this.store.each(function (r)   

                {  

                    var checked = !(!v.match(‘(^|’ + this.separator + ‘)’  

                                + RegExp.escape(r.get(this.valueField))  

                                + ‘(‘ + this.separator + ‘|$)’));  

                    r.set(this.checkField, checked);  

                }, this);  

                this.value = this.getCheckedValue();  

                this.setRawValue(this.getCheckedDisplay());  

                if (this.hiddenField)   

                {  

                    this.hiddenField.value = this.value;  

                }  

            }  

            else   

            {  

                this.value = v;  

                this.setRawValue(v);  

                if (this.hiddenField)   

                {  

                    this.hiddenField.value = v;  

                }  

            }  

            if (this.el)   

            {  

                this.el.removeClass(this.emptyClass);  

            }  

        }  

        else   

        {  

            this.clearValue();  

        }  

    },  

    selectAll: function ()   

    {  

        this.store.each(function (record)   

        {  

            record.set(this.checkField, true);  

        }, this);  

        this.doQuery(this.allQuery);  

        this.setValue(this.getCheckedValue());  

    },  

    deselectAll: function ()   

    {  

        this.clearValue();  

    }  

});  

Ext.reg(‘multiSelect’, Ext.form.MultiSelect);

2、在ext-all.css文件最後,加入css樣式

.ux-MultiSelect-icon { width:16px; height:16px; float:left; background-position: -1px -1px ! important; background-repeat:no-repeat ! important; }  

.ux-MultiSelect-icon-checked { background: transparent url(../images/default/menu/checked.gif); }  

.ux-MultiSelect-icon-unchecked { background: transparent url(../images/default/menu/unchecked.gif); }

3、使用

    var DepartUserStore=new Ext.data.Store(  

     {  

            proxy: new Ext.data.HttpProxy(  

            {  

                    url:’/Web/Manage/DeskTop/JSON/ScheduleManager/GetSimpleDepartUserInfo.aspx’  

            }),  

            //讀取Json  

            reader: new Ext.data.JsonReader(  

            { totalProperty: “totalCount”, root: “root” },   

            [  

                    {name:’UserId’,type:’int’},  

                    {name:’UserName’,type:’string’}  

            ])  

    });  

      

    var DepartUserCbox = new Ext.form.MultiSelect(  

    {  

            fieldLabel: ‘    姓名’,  

            labelStyle: ‘width:80px’,  

            width: 150,  

            editable: false,  

            id: ‘DepartUserDS’,  

            hiddenName:’DepartUserIdDS’,  

            store: DepartUserStore,  

            emptyText: ‘–請選擇–‘,  

            allowBlank: false,   

            blankText: ‘請選擇’,   

            mode:’remote’,  

            displayField: ‘UserName’,  

            valueField: ‘UserId’,  

            triggerAction: ‘all’,  

            selectOnFocus: true,  

            listWidth: 200  

    });  

      

    DepartUserStore.on(‘load’, function ()   

    {  

            DepartUserCbox.selectAll(); //全選  

    }); 

    

    DepartUserStore.load();

extjs 根據fieldset的checkBox情況,來全選checkBoxGroup

!doctype html

html lang=”en”

head

meta charset=”UTF-8″

titleExtjs 4.2 demo/title

link rel=”stylesheet” href=”../resources/css/ext-all.css”

script src=”../bootstrap.js”/script

script

Ext.onReady(function(){

Ext.create(‘Ext.Panel’,{

width:450,

items:[{

xtype: ‘checkboxgroup’,

listeners:{

change:function(gp,nv,ov,eOpts){

// 全選

if(nv.all  !ov.all) 

return gp.eachBox(function(box,idx){

box.setRawValue(true);

});

// 反選

if(ov.all  !nv.all)

return gp.eachBox(function(box,idx){

box.setRawValue(false);

});

}

},

width:’100%’,

fieldLabel: ‘Auto Layout’,

cls: ‘x-check-group-alt’,

items: [

{boxLabel: ‘全選’, name: ‘all’},

{boxLabel: ‘Item 1’, name: ‘cb-auto-1’, checked: true},

{boxLabel: ‘Item 2’, name: ‘cb-auto-2’},

{boxLabel: ‘Item 3’, name: ‘cb-auto-3’},

{boxLabel: ‘Item 4’, name: ‘cb-auto-4’}

]

},{

xtype:’button’,

text:’GetChecked’,

handler:function(){

Ext.Msg.alert(‘選中數量’,String(this.up(‘panel’).items.items[0].getChecked().length));

}

}],

renderTo:Ext.getBody()

});

});

/script

/head

body

/body

/html

extjs combobox樣式下拉框中如何添加複選框???

{ xtype: ‘combo’,

name: ‘status’,

id: ‘statusId’,

multiSelect: true,

editable: false,

emptyText: ‘ 策略執行狀態’,

queryMode: ‘local’,

store: status,

valueField: ‘id’,

displayField: ‘name’,

listConfig: {

itemTpl: ‘tpl for=”.”div class=”x-combo-list-item” onClick=”onClick(this)”spaninput type=”checkbox” value=”{[values.id]}” / {name}/span/div/tpl’,

},

queryMode: ‘local’,

triggerAction: ‘all’,

}

這樣寫不是更方便和直接么,而且獲取參數也比較簡單,得到的是個array

原創文章,作者:L2HS0,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/130129.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
L2HS0的頭像L2HS0
上一篇 2024-10-03 23:27
下一篇 2024-10-03 23:27

相關推薦

  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的“畫筆”在窗口中繪製…

    編程 2025-04-29
  • Python櫻花樹代碼簡單

    本文將對Python櫻花樹代碼進行詳細的闡述和講解,幫助讀者更好地理解該代碼的實現方法。 一、簡介 櫻花樹是一種圖形效果,它的實現方法比較簡單。Python中可以通過turtle這…

    編程 2025-04-28
  • Python大神作品:讓編程變得更加簡單

    Python作為一種高級的解釋性編程語言,一直被廣泛地運用於各個領域,從Web開發、遊戲開發到人工智能,Python都扮演着重要的角色。Python的代碼簡潔明了,易於閱讀和維護,…

    編程 2025-04-28
  • 用Python實現簡單爬蟲程序

    在當今時代,互聯網上的信息量是爆炸式增長的,其中很多信息可以被利用。對於數據分析、數據挖掘或者其他一些需要大量數據的任務,我們可以使用爬蟲技術從各個網站獲取需要的信息。而Pytho…

    編程 2025-04-28
  • 如何製作一個簡單的換裝遊戲

    本文將從以下幾個方面,為大家介紹如何製作一個簡單的換裝遊戲: 1. 遊戲需求和界面設計 2. 使用HTML、CSS和JavaScript開發遊戲 3. 實現遊戲的基本功能:拖拽交互…

    編程 2025-04-27
  • Guava Limiter——限流器的簡單易用

    本文將從多個維度對Guava Limiter進行詳細闡述,介紹其定義、使用方法、工作原理和案例應用等方面,並給出完整的代碼示例,希望能夠幫助讀者更好地了解和使用該庫。 一、定義 G…

    編程 2025-04-27
  • 2的32次方-1:一個看似簡單卻又複雜的數字

    對於計算機領域的人來說,2的32次方-1(也就是十進制下的4294967295)這個數字並不陌生。它經常被用來表示IPv4地址或者無符號32位整數的最大值。但實際上,這個數字卻包含…

    編程 2025-04-27
  • 製作一個簡單的管理系統的成本及實現

    想要製作一個簡單的管理系統,需要進行技術選型、開發、測試等過程,那麼這個過程會花費多少錢呢?我們將從多個方面來闡述製作一個簡單的管理系統的成本及實現。 一、技術選型 當我們開始思考…

    編程 2025-04-27

發表回復

登錄後才能評論