Serenity: How to set first row as default selected

Created on 26 Apr 2020  路  6Comments  路  Source: serenity-is/Serenity

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; }

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

All 6 comments

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]);
            });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Akarsh03 picture Akarsh03  路  3Comments

kilroyFR picture kilroyFR  路  3Comments

john20xdoe picture john20xdoe  路  3Comments

Amitloh picture Amitloh  路  3Comments

stixoffire picture stixoffire  路  3Comments