gpt4 book ai didi

javascript - 如何创建一个 dojo 数据网格,其中一列是标题行中的按钮?

转载 作者:行者123 更新时间:2023-11-30 12:51:10 25 4
gpt4 key购买 nike

我有一个 dojo(v1.6) 数据网格,它有复选框来选择行作为最左边的列。我需要将这些复选框的标题列作为删除按钮而不是全选复选框。单击删除按钮时,所有选定的行都会被删除。

请找到Data grid Demo .

我不知道如何将复选框的标题列作为按钮。请帮助我自定义小部件。这是网格 js 代码

dojo.ready(function(){
/*set up data store*/
var data = {
identifier: 'id',
items: []
};
var data_list = [
{ col1: "normal", col2: false, col3: 'But are not followed by two hexadecimal', col4: 29.91},
{ col1: "important", col2: false, col3: 'Because a % sign always indicates', col4: 9.33},
{ col1: "important", col2: false, col3: 'Signs can be selectively', col4: 19.34}
];
var rows = 10;
for(var i=0, l=data_list.length; i<rows; i++){
data.items.push(dojo.mixin({ id: i+1 }, data_list[i%l]));
}
var store = new dojo.data.ItemFileWriteStore({data: data});

/*set up layout*/
var layout = [
{ type: "dojox.grid._CheckBoxSelector" },
[
{'name': 'Column 1', 'field': 'id', 'width': '20%'},
{'name': 'Column 2', 'field': 'col2', 'width': '20%'},
{'name': 'Column 3', 'field': 'col3', 'width': '25%'},
{'name': 'Column 4', 'field': 'col4', 'width': '20%'}
]
];
/*create a new grid:*/
var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
cellOverClass: 'cellover'
},
document.createElement('div')
);
/*append the new grid to the div*/
dojo.byId("gridDiv").appendChild(grid.domNode);
/*Call startup() to render the grid*/
grid.startup();
});

HTML

<div id="gridDiv"></div>

最佳答案

您可以从现有 CheckBoxSelector 实现自己的 CheckBoxSelector。我通过查看 _Selector.js 源代码发现了这些方法。要覆盖的有趣方法是 generateHtmldoclick

参见 updated fiddle .

    dojo.declare('my.grid._CheckBoxSelector', [dojox.grid._CheckBoxSelector], {
_headerBuilderClass: dojo.extend(function (view) {
dojox.grid._HeaderBuilder.call(this, view);
}, dojox.grid._HeaderBuilder.prototype, {
generateHtml: function () {
var w = this.view.contentWidth || 0;
return '<table style="width:' + w + 'px;" ' +
'border="0" cellspacing="0" cellpadding="0" ' +
'role="presentation"><tr><th style="text-align: center;">' +
'<button data-dojo-type="dijit.form.Button" type="button">x</button><div class="dojoxGridCheckSelector dijitReset dijitInline dijitCheckBox" style="display:none"></div></th></tr></table>';
},
doclick: function (e) {
this.view.grid.removeSelectedRows();
return true;
}
})
});

/*set up layout*/
var layout = [{
type: "my.grid._CheckBoxSelector"
},

...

}]];

删除行

    this.view.grid.removeSelectedRows();

您可以在启动后解析网格以创建 dijit 小部件。

grid.startup();
// Not the best practice here but it should give you a starting point
// on where to find the header node.
dojo.parser.parse(grid.views.views[0].headerContentNode);

关于javascript - 如何创建一个 dojo 数据网格,其中一列是标题行中的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20918759/

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