@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
437 lines (380 loc) • 20.5 kB
text/typescript
/*
Copyright © 2016-2019 Lidor Systems. All rights reserved.
This file is part of the "IntegralUI Web" Library.
The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License.
A copy of the License should have been installed in the product's root installation directory or it can be found at
http://www.lidorsystems.com/products/web/studio/license-agreement.aspx.
This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language
governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws.
*/
import { Component, ViewContainerRef, ViewChild, ViewChildren, ViewEncapsulation } from '@angular/core';
import { IntegralUITreeGrid } from '../../integralui/components/integralui.treegrid';
export class TreeGridEventsSample {
applicationRef: ViewContainerRef;
treegrid: IntegralUITreeGrid;
// An array that holds treegrid columns
public columns: Array<any>;
// An array that holds treegrid rows
public rows: Array<any>;
public flatData: Array<any>;
public eventLog: Array<any> = [];
private rowCount: number = 8;
private rowIndex: number = -1;
public disableButtons: boolean = false;
public treegridStyle: any = {
general: {
normal: 'treegrid-evnts-normal'
}
}
constructor(){
this.columns = [
{ id: 1, headerText: "Customer/Order ID", headerAlignment: "center", width: 180 },
{ id: 2, headerText: "Ordered", headerAlignment: "center", contentAlignment: "center", width: 90 },
{ id: 3, headerText: "Shipped", headerAlignment: "center", contentAlignment: "center", width: 90 },
{ id: 4, headerText: "Ship Via", headerAlignment: "center", width: 125 },
{ id: 5, headerText: "Freight", headerAlignment: "center", contentAlignment: "right", width: 80 },
{ id: 6, headerText: "Address", headerAlignment: "center", width: 200 },
{ id: 7, headerText: "City", headerAlignment: "center" },
{ id: 8, headerText: "Country", headerAlignment: "center" }
];
this.rows = [];
this.flatData = [
{
id: 1,
icon: "icons-medium people",
text: "Piccolo und mehr",
cells: [{ cid: 1, text: "Piccolo und mehr" }, { cid: 6, text: "Geislweg 14" }, { cid: 7, text: "Salzburg" }, { cid: 8, text: "Austria" }]
},
{
id: 11,
pid: 1,
text: "Order #10259",
cells: [{ cid: 1, text: "10259" }, { cid: 2, text: "9/13/2012" }, { cid: 3, text: "9/27/2012" }, { cid: 4, text: "Federal Shipping" }, { cid: 5, text: "360.63" }]
},
{
id: 12,
pid: 1,
text: "Order #11094",
cells: [{ cid: 1, text: "11094" }, { cid: 2, text: "1/20/2013" }, { cid: 3, text: "2/5/2013" }, { cid: 4, text: "Federal Shipping" }, { cid: 5, text: "200.14" }]
},
{
id: 2,
icon: "icons-medium people",
text: "Frankenversand",
cells: [{ cid: 1, text: "Frankenversand" }, { cid: 6, text: "Berliner Platz 43" }, { cid: 7, text: "München" }, { cid: 8, text: "Germany" }]
},
{
id: 21,
pid: 2,
text: "Order #11536",
cells: [{ cid: 1, text: "11536" }, { cid: 2, text: "12/9/2013" }, { cid: 3, text: "1/7/2014" }, { cid: 4, text: "Speedy Express" }, { cid: 5, text: "85.53" } ]
},
{
id: 22,
pid: 2,
text: "Order #14472",
cells: [{ cid: 1, text: "14472" }, { cid: 2, text: "11/14/2014" }, { cid: 3, text: "11/25/2014" }, { cid: 4, text: "Speedy Express" }, { cid: 5, text: "112.30" } ]
},
{
id: 3,
icon: "icons-medium people",
text: "Laughing Bacchus Wine Cellars",
cells: [{ cid: 1, text: "Laughing Bacchus Wine Cellars" }, { cid: 6, text: "1900 Oak St." }, { cid: 7, text: "Vancouver" }, { cid: 8, text: "Canada" }]
},
{
id: 31,
pid: 3,
text: "Order #11495",
cells: [{ cid: 1, text: "11495" }, { cid: 2, text: "8/7/2013" }, { cid: 3, text: "9/20/2013" }, { cid: 4, text: "United Package" }, { cid: 5, text: "49.28" } ]
}
];
}
ngAfterViewInit(){
this.treegrid.loadData(this.flatData);
}
createNewRow(){
this.rowCount++;
let row: any = {
text: "Row " + this.rowCount,
cells: []
}
for (let j = 1; j <= this.columns.length; j++)
row.cells.push({ text: "Item" + this.rowCount + j });
return row;
}
add(){
let row: any = this.createNewRow();
this.treegrid.addRow(row);
this.treegrid.selectedRow = row;
this.disableButtons = false;
}
remove(){
if (this.treegrid.selectedRow)
this.treegrid.removeRow(this.treegrid.selectedRow);
}
clear(){
this.treegrid.clearRows();
}
selectNewRow(){
let list: Array<any> = this.treegrid.getList();
if (list && list.length > 0){
if (this.rowIndex == list.length)
this.rowIndex = list.length - 1;
if (this.rowIndex >= 0 && this.rowIndex < list.length){
if (this.rowIndex < list.length)
this.treegrid.selectedRow = list[this.rowIndex];
else
this.treegrid.selectedRow = list[list.length-1];
}
}
else
this.treegrid.selectedRow = null;
}
clearEventLog(){
this.eventLog.length = 0;
}
// Events
onAfterCollapse(e: any){
this.eventLog.unshift({ name: "afterCollapse", info: " event was fired after row is collapsed: ", value: e.row.text });
}
onAfterExpand(e: any){
this.eventLog.unshift({ name: "afterExpand", info: " event was fired after row is expanded: ", value: e.row.text });
}
onAfterSelect(e: any){
if (e.obj){
switch (e.obj.type){
case 'column':
this.eventLog.unshift({ name: "afterSelect", info: " event was fired after column is selected: ", value: e.obj.headerText });
break;
case 'row':
this.eventLog.unshift({ name: "afterSelect", info: " event was fired after row is selected: ", value: e.obj.text });
this.disableButtons = false;
break;
}
}
}
onBeforeCollapse(e: any){
this.eventLog.unshift({ name: "beforeCollapse", info: " event was fired before row is collapsed: ", value: e.row.text });
}
onBeforeExpand(e: any){
this.eventLog.unshift({ name: "beforeExpand", info: " event was fired before row is expanded: ", value: e.row.text });
}
onBeforeSelect(e: any){
if (e.obj){
switch (e.obj.type){
case 'column':
this.eventLog.unshift({ name: "beforeSelect", info: " event was fired before column is selected: ", value: e.obj.headerText });
break;
case 'row':
this.eventLog.unshift({ name: "beforeSelect", info: " event was fired before row is selected: ", value: e.obj.text });
break;
}
}
}
onDragOver(e: any){
this.eventLog.unshift({ name: "dragover", info: " event was fired when row is dragged over TreeGrid space" });
}
onDragDrop(e: any){
this.eventLog.unshift({ name: "dragdrop", info: " event was fired when drag-drop operation is completed" });
}
onKeyDown(e: any){
this.eventLog.unshift({ name: "keyDown", info: " event was fired when key is hold down while the cell has focus: ", value: e.cell.text });
}
onKeyPress(e: any){
this.eventLog.unshift({ name: "keyPress", info: " event was fired when key is pressed while the cell has focus: ", value: e.cell.text });
}
onKeyUp(e: any){
this.eventLog.unshift({ name: "keyUp", info: " event was fired when key is released while the cell has focus: ", value: e.cell.text });
}
onRowAdding(e: any){
this.eventLog.unshift({ name: "rowAdding", info: " event was fired before row is added: ", value: e.row.text });
}
onRowAdded(e: any){
this.eventLog.unshift({ name: "rowAdded", info: " event was fired after row is added: ", value: e.row.text });
this.disableButtons = false;
this.treegrid.updateLayout();
}
onRowClick(e: any){
this.eventLog.unshift({ name: "rowClick", info: " event was fired when " + e.row.text + " is clicked" });
}
onRowDblClick(e: any){
this.eventLog.unshift({ name: "rowDblclick", info: " event was fired when " + e.row.text + " is double-clicked" });
}
onClearRows(e: any){
this.eventLog.unshift({ name: "rowsCleared", info: " event was fired when all rows are removed at once", value: '' });
this.rowCount = 0;
this.disableButtons = true;
this.treegrid.updateLayout();
}
onRowRemoving(e: any){
this.eventLog.unshift({ name: "rowRemoving", info: " event was fired before row is removed: ", value: e.row.text });
this.rowIndex = -1;
let list: Array<any> = this.treegrid.getList();
if (list && list.length > 0)
this.rowIndex = list.indexOf(e.row);
}
onRowRemoved(e: any){
this.eventLog.unshift({ name: "rowRemoved", info: " event was fired after row is removed: ", value: e.row.text });
this.rowCount = this.rowCount > 0 ? this.rowCount - 1 : 0;
this.selectNewRow();
if (this.rowCount == 0)
this.disableButtons = true;
this.treegrid.updateLayout();
}
onScrollPosChanged(e: any){
this.eventLog.unshift({ name: "scrollPosChanged", info: " event was fired when scroll position changes: ", value: "{ x: " + e.value.x + ", y: " + e.value.y + " }" });
}
onSelectionChanged(){
this.eventLog.unshift({ name: "selectionChanged", info: " event was fired when selected column or row is changed." });
}
}