I Implemented RowSelectionModel in Grid. I want to make first row as default selected. how to do ti?
I try to use self.prodOrderItemGrid.slickGrid.setSelectedRows([items[0]]), but it didnot work.
protected createSlickGrid(): Slick.Grid {
var grid = super.createSlickGrid();
grid.setSelectionModel(new Slick.RowSelectionModel());
return grid;
}
You might need to call the layout update.. I forget the exact method - but it has to do with redrawing the layout .
@stixoffire Do you mean like below? but it didnot work
self.prodOrderItemGrid.element.triggerHandler("layout");
@Nathan2020-0126
Yes, however looking at a couple things - there are issues with slickGrid selection in the manner you describe. First lets see what we actually have .
1: Does the setSelectedRows([Item[0]]) exist ?
If not - then we need to determine how to reference the row ..
2: Is the row really defined as setSelectedRows([0])?
If 2 You would need to search the rows for that Item first and get the index and then set it. so IndexOf(Item[0])).
You could try this from #1192
you need to trigger its resizeCanvas method.
and the way to do that is:
$('.require-layout').filter(':visible').each(function (i, e) {
$(e).triggerHandler('layout');
});
Issue 1192
@stixoffire thanks for your detailed answers. I will try it and feedback here.
This should work (in grid constructor):
setTimeout(() => this.slickGrid.setSelectedRows([0]), 100);
Note: setSelectedRows wants an array of indexes, not entities
HTH
Hannes
@hannesb It works. thank you very much. I used as below
self.prodOrderItemGrid.view.onDataLoaded.subscribe(e => {
self.prodOrderItemGrid.slickGrid.setSelectedRows([0]);
});
Most helpful comment
This should work (in grid constructor):
setTimeout(() => this.slickGrid.setSelectedRows([0]), 100);Note: setSelectedRows wants an array of indexes, not entities
HTH
Hannes