|
92 | 92 | } |
93 | 93 |
|
94 | 94 | _computeLength(rawItems) { |
95 | | - return this.rawItems.length; |
| 95 | + const rawItems = this.rawItems || []; |
| 96 | + return rawItems.length; |
96 | 97 | } |
97 | 98 |
|
98 | 99 | _ramItemsChanged() { |
|
105 | 106 | } |
106 | 107 |
|
107 | 108 | _updatePage() { |
108 | | - |
109 | | - console.log('pageIndex, pageSize',this.pageIndex, this.pageSize); |
110 | | - |
111 | 109 | if(this.rawItems === undefined) { |
112 | 110 | return; |
113 | 111 | } |
114 | 112 | /* Make sure to always start with same array to ensure consistency in sorting results */ |
115 | | - var workArray = this.rawItems.slice(); |
116 | | - var start = (this.pageIndex * this.pageSize); |
| 113 | + const workArray = this.rawItems.slice(); |
| 114 | + const start = (this.pageIndex * this.pageSize); |
117 | 115 |
|
118 | 116 | console.log('start, this._doSort', start, this._doSort); |
119 | 117 |
|
120 | 118 | if(this._doSort && this.sorted) { |
121 | | - var lookupItemByPath = (item, path) => { |
122 | | - var parts = path.split("."); |
| 119 | + const lookupItemByPath = (item, path) => { |
| 120 | + const parts = path.split("."); |
123 | 121 | if (parts.length === 1){ |
124 | 122 | return item[parts[0]]; |
125 | 123 | } |
126 | 124 | return lookupItemByPath(item[parts[0]], parts.slice(1).join(".")); |
127 | 125 | }; |
128 | 126 |
|
129 | 127 | workArray.sort((a, b) => { |
130 | | - var fieldA = lookupItemByPath(a, this.sorted); |
131 | | - var fieldB = lookupItemByPath(b, this.sorted); |
| 128 | + const fieldA = lookupItemByPath(a, this.sorted); |
| 129 | + const fieldB = lookupItemByPath(b, this.sorted); |
132 | 130 | if(typeof fieldA === 'number' || typeof fieldA === 'boolean') { |
133 | 131 | return this.sortDirection === 'ASC' ? fieldA - fieldB : fieldB - fieldA; |
134 | 132 | } else { |
|
148 | 146 | } |
149 | 147 |
|
150 | 148 | this.set('items', []); |
151 | | - |
152 | | - console.log('start, this._doSort', workArray, workArray.slice(start, start + this.pageSize)); |
153 | 149 | this.set('items', workArray.slice(start, start + this.pageSize)); |
154 | | - // for(var i = start; i < start + this.pageSize; i++) { |
155 | | - // if(workArray[i] !== undefined) { |
156 | | - // this.push('items', workArray[i]); |
157 | | - // } |
158 | | - // } |
159 | 150 | } |
160 | 151 |
|
161 | 152 | } |
|
0 commit comments