gpt4 book ai didi

extjs - ExtJS 4选择带有复选框标题的多个CheckColumn复选框

转载 作者:行者123 更新时间:2023-12-04 13:42:06 27 4
gpt4 key购买 nike

我有一列checkcolumn类型来启用切换 bool 值。我希望能够一次为该值切换所有行。理想情况下,我可以在checkcolumn header 中添加一个复选框,并监听更改。那可能吗?

我想指出的是,我不是在寻找用于选择行的checkboxmodel。

最佳答案

我为此创建了一个Ext.ux.CheckColumn的更新版本,只需在包含extjs代码后包括以下代码即可:

Ext.define('Ext.ux.CheckColumn', {
extend: 'Ext.grid.column.Column',
alias: 'widget.checkcolumn',

disableColumn: false,
disableFunction: null,
disabledColumnDataIndex: null,
columnHeaderCheckbox: false,

constructor: function(config) {

var me = this;
if(config.columnHeaderCheckbox)
{
var store = config.store;
store.on("datachanged", function(){
me.updateColumnHeaderCheckbox(me);
});
store.on("update", function(){
me.updateColumnHeaderCheckbox(me);
});
config.text = me.getHeaderCheckboxImage(store, config.dataIndex);
}

me.addEvents(
/**
* @event checkchange
* Fires when the checked state of a row changes
* @param {Ext.ux.CheckColumn} this
* @param {Number} rowIndex The row index
* @param {Boolean} checked True if the box is checked
*/
'beforecheckchange',
/**
* @event checkchange
* Fires when the checked state of a row changes
* @param {Ext.ux.CheckColumn} this
* @param {Number} rowIndex The row index
* @param {Boolean} checked True if the box is checked
*/
'checkchange'
);

me.callParent(arguments);
},

updateColumnHeaderCheckbox: function(column){
var image = column.getHeaderCheckboxImage(column.store, column.dataIndex);
column.setText(image);
},

toggleSortState: function(){
var me = this;
if(me.columnHeaderCheckbox)
{
var store = me.up('tablepanel').store;
var isAllChecked = me.getStoreIsAllChecked(store, me.dataIndex);
store.each(function(record){
record.set(me.dataIndex, !isAllChecked);
record.commit();
});
}
else
me.callParent(arguments);
},

getStoreIsAllChecked: function(store, dataIndex){
var allTrue = true;
store.each(function(record){
if(!record.get(dataIndex))
allTrue = false;
});
return allTrue;
},

getHeaderCheckboxImage: function(store, dataIndex){

var allTrue = this.getStoreIsAllChecked(store, dataIndex);

var cssPrefix = Ext.baseCSSPrefix,
cls = [cssPrefix + 'grid-checkheader'];

if (allTrue) {
cls.push(cssPrefix + 'grid-checkheader-checked');
}
return '<div class="' + cls.join(' ') + '">&#160;</div>'
},

/**
* @private
* Process and refire events routed from the GridView's processEvent method.
*/
processEvent: function(type, view, cell, recordIndex, cellIndex, e) {
if (type == 'mousedown' || (type == 'keydown' && (e.getKey() == e.ENTER || e.getKey() == e.SPACE))) {
var record = view.panel.store.getAt(recordIndex),
dataIndex = this.dataIndex,
checked = !record.get(dataIndex),
column = view.panel.columns[cellIndex];
if(!(column.disableColumn || record.get(column.disabledColumnDataIndex) || (column.disableFunction && column.disableFunction(checked, record))))
{
if(this.fireEvent('beforecheckchange', this, recordIndex, checked, record))
{
record.set(dataIndex, checked);
this.fireEvent('checkchange', this, recordIndex, checked, record);
}
}
// cancel selection.
return false;
} else {
return this.callParent(arguments);
}
},

// Note: class names are not placed on the prototype bc renderer scope
// is not in the header.
renderer : function(value, metaData, record, rowIndex, colIndex, store, view){
var disabled = "",
column = view.panel.columns[colIndex];
if(column.disableColumn || column.disabledColumnDataIndex || (column.disableFunction && column.disableFunction(value, record)))
disabled = "-disabled";
var cssPrefix = Ext.baseCSSPrefix,
cls = [cssPrefix + 'grid-checkheader' + disabled];

if (value) {
cls.push(cssPrefix + 'grid-checkheader-checked' + disabled);
}
return '<div class="' + cls.join(' ') + '">&#160;</div>';
}
});

那么复选框列的示例设置将如下所示:
{
xtype: "checkcolumn",
columnHeaderCheckbox: true,//this setting is necessary for what you want
store: (you need to put the grids store here),
sortable: false,
hideable: false,
menuDisabled: true,
dataIndex: "value_flag",
listeners: {
checkchange: function(column, rowIndex, checked){
//code for whatever on checkchange here
}
}
}

看起来像这样:

关于extjs - ExtJS 4选择带有复选框标题的多个CheckColumn复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393660/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com