@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
314 lines (269 loc) • 13.4 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 { IntegralUIDateFormat, IntegralUIEditorType, IntegralUIVisibility } from '../../integralui/components/integralui.core';
import { IntegralUIGrid } from '../../integralui/components/integralui.grid';
export class GridBuiltinEditorsSample {
applicationRef: ViewContainerRef;
grid: IntegralUIGrid;
public columns: Array<any>;
public rows: Array<any>;
public gridStyle: any = {
general: {
normal: 'grid-btinedit-normal'
}
}
private dropListItems: Array<any> = [
{ value: "Action" },
{ value: "Adventure" },
{ value: "Comedy " },
{ value: "Drama " },
{ value: "Horror " },
{ value: "Mystery " },
{ value: "Romance " },
{ value: "Sci-Fi" }
];
constructor(){
this.columns = [];
this.rows = [];
}
ngAfterViewInit(){
this.add();
}
addColumns(){
for (let j = 1; j <= 10; j++){
let column: any = {
id: j,
title: "Header " + j,
footerText: "Footer " + j
}
switch (j){
case 1:
column.editorType = IntegralUIEditorType.Label;
column.editorSettings = {
threeState: true
}
column.title = "Label";
column.width = 80;
break;
case 2:
column.editorType = IntegralUIEditorType.CheckBox;
column.editorSettings = {
threeState: true
}
column.title = "CheckBox";
column.width = 60;
column.fixedWidth = true;
break;
case 3:
column.editorType = IntegralUIEditorType.Date;
column.editorSettings = {
locales: 'en-GB',
format: IntegralUIDateFormat.Custom,
formatOptions: {
year: 'numeric',
month: 'short',
day: '2-digit'
}
}
column.title = "Date";
column.width = 130;
break;
case 4:
column.editorType = IntegralUIEditorType.Rating;
column.editorSettings = {
style: {
general: {
normal: 'grid-btinedit-rating'
}
}
}
column.title = "Rating";
break;
case 5:
column.editorType = IntegralUIEditorType.DropList;
column.editorSettings = {
items: this.dropListItems,
minWidth: 150,
maxVisibleItems: 4
}
column.title = "DropList";
column.width = 120;
break;
case 6:
column.editorType = IntegralUIEditorType.Progress;
column.title = "Progress";
break;
case 7:
column.editorType = IntegralUIEditorType.Numeric;
column.editorSettings = {
min: 0,
max: 100
}
column.title = "Numeric";
column.width = 50;
break;
case 8:
column.editorType = IntegralUIEditorType.TextBox;
column.title = "TextBox";
column.width = 80;
break;
case 9:
column.editorType = IntegralUIEditorType.Image;
column.title = "Image";
break;
case 10:
// Custom, editorType is not required
// The cell content is determined by specified HTML template
column.title = "Custom";
column.width = 150;
break;
}
this.columns.push(column);
}
}
addRows(){
for (let i = 1; i <= 100; i++){
let row: any = {
text : 'Row ' + i.toString(),
id: i,
cells: [],
rows: []
};
for (let j = 1; j <= this.columns.length; j++){
let cell: any = {
cid: j,
text: "Item" + i + j
}
// For cell editors, the value field is used to specify the cell value
// In case of Label and TextBox, instead of value, the text field is in use.
switch (j){
case 2: //CheckBox
if (this.getRandomNumber() % 3 == 1)
cell.value = 'checked';
else if (this.getRandomNumber() % 3 == 2)
cell.value = 'indeterminate';
else
cell.value = 'unchecked';
break;
case 3: // Date
cell.value = new Date(2018, 8, (i+j) * 3);
break;
case 4: // Rating
cell.value = this.getRandomNumber();
break;
case 5: // DropList
cell.value = this.dropListItems[i % this.dropListItems.length].value;
break;
case 6: // Progress
cell.value = this.getRandomNumber() * 5;
break;
case 7: // Numeric
cell.value = this.getRandomNumber();
break;
case 9: // Image
cell.value = [];
switch (i % 4){
case 1:
cell.value.push({ src: 'app/resources/checkbox/checkbox-checked-5.png' });
cell.value.push({ src: 'app/resources/checkbox/checkbox-checked-4.png' });
break;
case 2:
cell.value.push({ src: 'app/resources/radiobutton/radio-checked.png' });
cell.value.push({ src: 'app/resources/checkbox/checkbox-indeterminate-7.png' });
cell.value.push({ src: 'app/resources/expandbox/expand-red.png' });
break;
case 3:
cell.value.push({ src: 'app/resources/expandbox/expand-green.png' });
cell.value.push({ src: 'app/resources/radiobutton/radio-checked-2.png' });
break;
default:
cell.value.push({ src: 'http://www.lidorsystems.com/favicon.ico' });
break;
}
break;
}
row.cells.push(cell);
}
this.rows.push(row);
}
}
add(){
this.clear();
this.addColumns();
this.addRows();
this.grid.updateLayout();
}
clear(){
this.grid.clearColumns();
this.grid.clearRows();
this.grid.updateLayout();
}
getRandomNumber(){
return 1 + Math.floor(Math.random() * 10);
}
gridCellValueBefore(e: any){
console.log("cellValueChanging: ", e);
}
gridCellValueAfter(e: any){
console.log("cellValueChanged: ", e);
}
}