@syncfusion/ej2-grids
Version:
Feature-rich JavaScript datagrid (datatable) control with built-in support for editing, filtering, grouping, paging, sorting, and exporting to Excel.
97 lines (96 loc) • 4.34 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { CheckBox } from '@syncfusion/ej2-buttons';
import { extend } from '@syncfusion/ej2-base';
import { isEditable, addRemoveActiveClasses, createEditElement, getObject } from '../base/util';
import * as literals from '../base/string-literals';
import { EditCellBase } from './edit-cell-base';
/**
* `BooleanEditCell` is used to handle boolean cell type editing.
*
* @hidden
*/
var BooleanEditCell = /** @class */ (function (_super) {
__extends(BooleanEditCell, _super);
function BooleanEditCell() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.activeClasses = ['e-selectionbackground', 'e-active'];
return _this;
}
BooleanEditCell.prototype.create = function (args) {
var col = args.column;
var classNames = 'e-field e-boolcell';
if (col.type === 'checkbox') {
classNames = 'e-field e-boolcell e-edit-checkselect';
}
this.removeEventHandler = this.removeEventListener;
return createEditElement(this.parent, args.column, classNames, { type: 'checkbox', value: args.value });
};
BooleanEditCell.prototype.read = function (element) {
return element.checked;
};
BooleanEditCell.prototype.write = function (args) {
var selectChkBox;
var chkState;
if (!isNullOrUndefined(args.row)) {
selectChkBox = args.row.querySelector('.e-edit-checkselect');
}
if (getObject(args.column.field, args.rowData)) {
chkState = JSON.parse(getObject(args.column.field, args.rowData).toString().toLowerCase());
}
if (!isNullOrUndefined(selectChkBox) && args.column.type === 'checkbox') {
this.editType = this.parent.editSettings.mode;
this.editRow = args.row;
if (args.requestType !== 'add') {
var row = this.parent.getRowObjectFromUID(args.row.getAttribute('data-uid'));
chkState = row ? row.isSelected : false;
}
addRemoveActiveClasses.apply(void 0, [[].slice.call(args.row.getElementsByClassName(literals.rowCell)), chkState].concat(this.activeClasses));
}
this.obj = new CheckBox(extend({
label: this.parent.editSettings.mode !== 'Dialog' ? ' ' : args.column.headerText,
checked: chkState,
disabled: !isEditable(args.column, args.requestType, args.element), enableRtl: this.parent.enableRtl,
cssClass: this.parent.cssClass ? this.parent.cssClass : ''
}, args.column.edit.params));
this.addEventListener();
this.obj.appendTo(args.element);
};
BooleanEditCell.prototype.addEventListener = function () {
this.cbChange = this.checkBoxChange.bind(this);
this.obj.addEventListener(literals.change, this.cbChange);
};
BooleanEditCell.prototype.removeEventListener = function () {
if (this.obj.isDestroyed) {
return;
}
this.obj.removeEventListener(literals.change, this.cbChange);
};
BooleanEditCell.prototype.checkBoxChange = function (args) {
if (this.editRow && this.editType !== 'Dialog') {
var add = false;
if (!args.checked) {
this.editRow.removeAttribute('aria-selected');
}
else {
add = true;
this.editRow.setAttribute('aria-selected', add.toString());
}
addRemoveActiveClasses.apply(void 0, [[].slice.call(this.editRow.getElementsByClassName(literals.rowCell)), add].concat(this.activeClasses));
}
};
return BooleanEditCell;
}(EditCellBase));
export { BooleanEditCell };