您好,我这边有限制,没法发demo上去,拷贝一下主要代码
- this.initialize({
- autoGenerateColumns: false,
- itemFormatter: (panel, r, c, cell) => {
- if (panel.cellType == wjcGrid.CellType.ColumnHeader) {
- let flex = panel.grid;
- let col = flex.columns[c];
- // check that this is a boolean column
- if (col.dataType == wjcCore.DataType.Boolean) {
- // prevent sorting on click
- col.allowSorting = false;
- // count true values to initialize checkbox
- var cnt = 0;
- for (var i = 0; i < flex.rows.length; i++) {
- if (flex.getCellData(i, c) == true) cnt++;
- }
- // create and initialize checkbox
- cell.innerHTML = '<input type="checkbox"> ';
- var cb = cell.firstChild;
- cb.checked = cnt > 0;
- cb.indeterminate = cnt > 0 && cnt < flex.rows.length;
- // apply checkbox value to cells
- cb.addEventListener('click', (e) => {
- flex.beginUpdate();
- for (var i = 0; i < flex.rows.length; i++) {
- flex.setCellData(i, c, cb.checked);
- }
- this.dataTest();
- flex.endUpdate();
- });
- }
- }
- },
- cellEditEnding: (s, e) => {
- var col = s.columns[e.col];
- if (col.binding == this._myProperty) {
- setTimeout(() => {
- this.dataTest();
- });
- }
- },
- // 主要代码如下
- columns: [
- { binding: 'template', header: 'Template', width: 130, isReadOnly: true },
- ],
- showAlternatingRows: false,
- formatItem: (s, e) => {
- if (e.panel == s.cells && s.columns[e.col].binding == 'template') {
- let item = s.rows[e.row].dataItem,
- html = wjcCore.format(theTemplate, item);
- e.cell.innerHTML = html;
- }
- }
- });
复制代码
|