Skip to content

Commit b88d88f

Browse files
committed
feat (grid-ctx): more utility functions
Breaking change: -set and get columns not needs a array and returns a array New features -set columns set also internal column count -reGenerateColumns(resetScrollToTop) redraws the columns, to be used after setting columns -orderby(sortArray) for doing multi-sort by code
1 parent e0283b4 commit b88d88f

File tree

1 file changed

+75
-5
lines changed

1 file changed

+75
-5
lines changed

src/vGrid/v-grid-ctx.js

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ export class VGridCtx {
251251
/****************************************************************************************************************************
252252
* explain
253253
****************************************************************************************************************************/
254-
setColumns(paramObj) {
255-
this.vGridConfig.colConfig = paramObj.colConfig;
254+
setColumns(paramArray) {
255+
this.vGridConfig.colConfig = paramArray;
256+
this.vGrid.vGridConfig.columnLength = paramArray.length
256257
};
257258

258259

@@ -272,12 +273,81 @@ export class VGridCtx {
272273
}
273274
arr.push(x);
274275
});
275-
return {
276-
"colConfig": arr
277-
}
276+
return arr
278277
};
279278

280279

280+
/****************************************************************************************************************************
281+
* explain
282+
****************************************************************************************************************************/
283+
reGenerateColumns(resetScrollToTop) {
284+
this.vGrid.vGridMarkupGenerator.generate();
285+
this.vGridGenerator.columnChangeAndCollection(resetScrollToTop);
286+
};
287+
288+
289+
/****************************************************************************************************************************
290+
* explain
291+
****************************************************************************************************************************/
292+
orderBy(sortArray) {
293+
294+
295+
//can we do the sorting?
296+
if (this.vGrid.vGridCollectionFiltered.length > 0) {
297+
//set loading screen
298+
if (this.vGrid.vGridCollection.length > this.vGridConfig.attLoadingThreshold) {
299+
this.vGrid.loading = true;
300+
}
301+
302+
//set query
303+
setTimeout(()=> {
304+
305+
this.vGrid.vGridSort.reset();
306+
//set filter
307+
sortArray.forEach((sort)=>{
308+
this.vGrid.vGridSort.setFilter({
309+
attribute: sort.attribute,
310+
asc: sort.asc
311+
}, true);
312+
});
313+
314+
let event = new CustomEvent("sortIconUpdate", {
315+
detail: "",
316+
bubbles: true
317+
});
318+
this.vGrid.element.dispatchEvent(event);
319+
320+
//if remote call is set
321+
if (this.vGridConfig.eventOnRemoteCall) {
322+
323+
//trigger remote call
324+
this.vGridConfig.remoteCall();
325+
326+
} else {
327+
//run filter
328+
this.vGrid.vGridSort.run(this.vGrid.vGridCollectionFiltered);
329+
330+
//set new row
331+
if (this.vGrid.vGridCurrentEntityRef) {
332+
this.vGrid.vGridCollectionFiltered.forEach((x, index) => {
333+
if (this.vGrid.vGridCurrentEntityRef[this.vGrid.vGridRowKey] === x[this.vGrid.vGridRowKey]) {
334+
this.vGrid.vGridCurrentRow = index;
335+
}
336+
});
337+
}
338+
339+
//update grid
340+
this.vGrid.vGridGenerator.collectionChange();
341+
this.vGrid.loading = false;
342+
}
343+
344+
}, 50);
345+
}
346+
347+
348+
}
349+
350+
281351
/****************************************************************************************************************************
282352
* explain
283353
****************************************************************************************************************************/

0 commit comments

Comments
 (0)