|
| 1 | +import { Component, VERSION } from '@angular/core'; |
| 2 | +import { ViewChild, OnInit, AfterViewInit } from '@angular/core'; |
| 3 | +import { GridComponent, GridColumn, DataAdapter, Smart } from 'smart-webcomponents-angular/grid'; |
| 4 | + |
| 5 | +interface IRowGenerateData { |
| 6 | + id: number; |
| 7 | + reportsTo: number | null; |
| 8 | + available: boolean | null; |
| 9 | + firstName: string; |
| 10 | + lastName: string; |
| 11 | + name: string; |
| 12 | + productName: string; |
| 13 | + quantity: string | number; |
| 14 | + total: string | number; |
| 15 | + price: string | number; |
| 16 | + date: Date; |
| 17 | + leaf: boolean; |
| 18 | +} |
| 19 | + |
| 20 | +interface IRowGenerateOrdersData { |
| 21 | + id: number | string; |
| 22 | + parentid: number | null; |
| 23 | + customer: string; |
| 24 | + firstName: string; |
| 25 | + lastName: string; |
| 26 | + name: string; |
| 27 | + price: string | number; |
| 28 | + quantity: string | number; |
| 29 | + total: string | number; |
| 30 | + date: Date; |
| 31 | +} |
| 32 | + |
| 33 | +interface ITaskGenerateData { |
| 34 | + id: number | string; |
| 35 | + status: string; |
| 36 | + text: string; |
| 37 | + tags?: string; |
| 38 | + priority?: string; |
| 39 | + progress?: number; |
| 40 | + checklist?: { text: string, completed: boolean }[]; |
| 41 | + color?: string; |
| 42 | + comments?: { text: string, userId: number | string, time: Date }[]; |
| 43 | + userId?: number | string; |
| 44 | + startDate?: Date; |
| 45 | + dueDate?: Date |
| 46 | +} |
| 47 | + |
| 48 | +export function GetData(rowscount?: number, last?: number, hasNullValues?: boolean): IRowGenerateData[] { |
| 49 | + const data: IRowGenerateData[] = new Array(); |
| 50 | + |
| 51 | + if (rowscount === undefined) { |
| 52 | + rowscount = 100; |
| 53 | + } |
| 54 | + |
| 55 | + let startIndex = 0; |
| 56 | + |
| 57 | + if (last) { |
| 58 | + startIndex = rowscount; |
| 59 | + rowscount = last - rowscount; |
| 60 | + } |
| 61 | + |
| 62 | + const firstNames = |
| 63 | + [ |
| 64 | + 'Andrew', 'Nancy', 'Shelley', 'Regina', 'Yoshi', 'Antoni', 'Mayumi', 'Ian', 'Peter', 'Lars', 'Petra', 'Martin', 'Sven', 'Elio', 'Beate', 'Cheryl', 'Michael', 'Guylene' |
| 65 | + ]; |
| 66 | + |
| 67 | + const lastNames = |
| 68 | + [ |
| 69 | + 'Fuller', 'Davolio', 'Burke', 'Murphy', 'Nagase', 'Saavedra', 'Ohno', 'Devling', 'Wilson', 'Peterson', 'Winkler', 'Bein', 'Petersen', 'Rossi', 'Vileid', 'Saylor', 'Bjorn', 'Nodier' |
| 70 | + ]; |
| 71 | + |
| 72 | + const productNames = |
| 73 | + [ |
| 74 | + 'Black Tea', 'Green Tea', 'Caffe Espresso', 'Doubleshot Espresso', 'Caffe Latte', 'White Chocolate Mocha', 'Caramel Latte', 'Caffe Americano', 'Cappuccino', 'Espresso Truffle', 'Espresso con Panna', 'Peppermint Mocha Twist' |
| 75 | + ]; |
| 76 | + |
| 77 | + const priceValues = |
| 78 | + [ |
| 79 | + '2.25', '1.5', '3.0', '3.3', '4.5', '3.6', '3.8', '2.5', '5.0', '1.75', '3.25', '4.0' |
| 80 | + ]; |
| 81 | + |
| 82 | + for (let i = 0; i < rowscount; i++) { |
| 83 | + const row = {} as IRowGenerateData; |
| 84 | + |
| 85 | + const productindex = Math.floor(Math.random() * productNames.length); |
| 86 | + const price = parseFloat(priceValues[productindex]); |
| 87 | + const quantity = 1 + Math.round(Math.random() * 10); |
| 88 | + |
| 89 | + row.id = startIndex + i; |
| 90 | + row.reportsTo = Math.floor(Math.random() * firstNames.length); |
| 91 | + |
| 92 | + if (i % Math.floor(Math.random() * firstNames.length) === 0) { |
| 93 | + row.reportsTo = null; |
| 94 | + } |
| 95 | + |
| 96 | + row.available = productindex % 2 === 0; |
| 97 | + |
| 98 | + if (hasNullValues === true) { |
| 99 | + if (productindex % 2 !== 0) { |
| 100 | + const random = Math.floor(Math.random() * rowscount); |
| 101 | + row.available = i % random === 0 ? null : false; |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + row.firstName = firstNames[Math.floor(Math.random() * firstNames.length)]; |
| 106 | + row.lastName = lastNames[Math.floor(Math.random() * lastNames.length)]; |
| 107 | + row.name = row.firstName + ' ' + row.lastName; |
| 108 | + row.productName = productNames[productindex]; |
| 109 | + row.price = price; |
| 110 | + row.quantity = quantity; |
| 111 | + row.total = price * quantity; |
| 112 | + |
| 113 | + const date = new Date(); |
| 114 | + date.setFullYear(2016, Math.floor(Math.random() * 11), Math.floor(Math.random() * 27)); |
| 115 | + date.setHours(0, 0, 0, 0); |
| 116 | + row.date = date; |
| 117 | + |
| 118 | + data[i] = row; |
| 119 | + } |
| 120 | + |
| 121 | + return data; |
| 122 | +} |
| 123 | + |
| 124 | + |
| 125 | +@Component({ |
| 126 | + selector: 'my-app', |
| 127 | + templateUrl: './app.component.html', |
| 128 | + styleUrls: [ './app.component.css' ] |
| 129 | +}) |
| 130 | +export class AppComponent { |
| 131 | + name = 'Angular ' + VERSION.major; |
| 132 | + |
| 133 | + @ViewChild('grid', { read: GridComponent, static: false }) grid: GridComponent; |
| 134 | + |
| 135 | + public appearance = { |
| 136 | + alternationStart: 0, |
| 137 | + alternationCount: 2, |
| 138 | + showRowHeader: true, |
| 139 | + showRowHeaderFocusIcon: true, |
| 140 | + showRowHeaderSelectIcon: true |
| 141 | + }; |
| 142 | + |
| 143 | + public selection = { |
| 144 | + enabled: true, |
| 145 | + mode: 'one', |
| 146 | + allowRowHeaderSelection: true |
| 147 | + }; |
| 148 | + |
| 149 | + public pager = { |
| 150 | + visible: true |
| 151 | + }; |
| 152 | + |
| 153 | + public paging = { |
| 154 | + enabled: true |
| 155 | + }; |
| 156 | + |
| 157 | + public layout = { |
| 158 | + rowHeight: 'auto', |
| 159 | + allowCellsWrap: true |
| 160 | + }; |
| 161 | + |
| 162 | + dataSource = new Smart.DataAdapter({ |
| 163 | + dataSource: GetData(1000), |
| 164 | + dataFields: [ |
| 165 | + 'id: number', |
| 166 | + 'firstName: string', |
| 167 | + 'lastName: string', |
| 168 | + 'productName: string', |
| 169 | + 'quantity: number', |
| 170 | + 'price: number', |
| 171 | + 'total: number' |
| 172 | + ] |
| 173 | + }); |
| 174 | + |
| 175 | + columns: GridColumn[] = [ |
| 176 | + { label: 'First Name', dataField: 'firstName' }, |
| 177 | + { label: 'Last Name', dataField: 'lastName' }, |
| 178 | + { label: 'Product', dataField: 'productName' }, |
| 179 | + { label: 'Quantity', dataField: 'quantity', align: 'right', cellsAlign: 'right' }, |
| 180 | + { label: 'Unit Price', dataField: 'price', align: 'right', cellsAlign: 'right', cellsFormat: 'c2' }, |
| 181 | + { label: 'Total', dataField: 'total', align: 'right', cellsAlign: 'right', cellsFormat: 'c2' } |
| 182 | + ] |
| 183 | + |
| 184 | +} |
0 commit comments