set web component grid initial sort using script

Hi

we are using the vaadin grid html web component v 5.2.5 and I’m trying to get the grid’s initial sort set using script rather than declaratively using the polymer template.

I have a sort order passed in from an external component and I can use this to pass to my server call to get the external data but as the grid doesn’t know about this, the sortOrders member of the param for the dataProvider callback isn’t set and so, I assume, the grid doesn’t show the appropriate sort order in the headers.

Is there a way to set the grid’s sort using script? The component which contains the grid is intended to be generic so I can’t hard code the sort order or column names.

eg grid.sort=[{path:“ID”, direction:“asc”}, …]
;

Thanks

Jon

Hello. In case you need to only set one sorter, you can do it like this:

grid.querySelector('vaadin-grid-sorter[path="lastName"]
').direction = 'asc';

Regarding the sorting priority for multi-sort case, the API for that was requested here:
https://github.com/vaadin/vaadin-grid/issues/1183

OK thanks - had worked it out similarly to this too but was also wondering about multi-level sorts