serenity.is handle row selection
//// In MyEntityGrid.ts
private rowSelection: Serenity.GridRowSelectionMixin;
protected createToolbarExtensions() {
super.createToolbarExtensions();
this.rowSelection = new Serenity.GridRowSelectionMixin(this);
}
protected getItemCssClass(item: MyEntityRow, index: number): string {
var klass = super.getItemCssClass(item, index);
if (item.MyValue > -1) // we use MyValue row field as filter
klass += " inactive";
return Q.trimToNull(klass);
}
constructor(container: JQuery) {
super(container);
$('span.select-all-items').on("click", (e) => {
if (this.rowSelection.getSelectedKeys().length > 0) {
setTimeout(() => {
this.rowSelection.resetCheckedAndRefresh();
this.rowSelection.setSelectedKeys([]);
}, 5);
} else {
var items = this.getView().getItems();
var selectables: any = items.filter((item) => { return item.MyValue == -1 }).map(el => String(el.Id));
setTimeout(() => {
this.rowSelection.resetCheckedAndRefresh();
this.rowSelection.setSelectedKeys(selectables);
}, 5);
}
});
this.getGrid().onClick.subscribe((e, p) => {
if ($(e.target).hasClass('select-item check-box')) {
//var item = this.getView().getItem(p.row);
var items = this.getView().getItems();
var selectables: any = items.filter((item) => { return item.MyValue == -1 });
var mySelection = this.rowSelection.getSelectedKeys().filter((v, i) => selectables.findIndex(item => item.Id == v) != -1);
this.rowSelection.resetCheckedAndRefresh();
this.rowSelection.setSelectedKeys(mySelection);
}
});
};