This is a migrated thread and some comments may be shown as answers.

Is there a way to access grid from inside @code block?

3 Answers 327 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wei
Top achievements
Rank 1
Wei asked on 26 Nov 2019, 02:57 AM

once a grid is declared in markup, and for columns that are sortable, reorderable and resizable. I want to persist that settting from grid UI and later apply those settings back to grid, in @code section (some event handler handles save column setting, apply column settings)?

this requires @code block to be able to access the grid object and the columns inside it. it is possible? 

3 Answers, 1 is accepted

Sort by
0
Wei
Top achievements
Rank 1
answered on 26 Nov 2019, 03:38 AM

I added @ref in grid markup and declared the grid in @code block. 

this.grid.GridColumns

this returns renderFragment object, how do I get each column and its properties

thanks

0
Marin Bratanov
Telerik team
answered on 26 Nov 2019, 08:51 AM

Hello Wei, 

You can Follow the implementation of such a feature in the following page (I added your Vote for you): https://feedback.telerik.com/blazor/1414050-save-grid-layout. It would require a lot of other things as base though, such as programmatic filtering, sorting and so on (also available in our Feedback Portal if you want to follow them - here, here, here, here).

The way to get information for columns is to define a view model with the data you want and use that to fill in the columns collection. A similar example is available in the following pages:

You can use this approach to apply settings to the grid when it initializes, but extracting that information is mostly unavailable at the moment. You could handle the OnRead event to implement all read operations yourself, and to store the DataSourceRequest object from which you could extract information about filter, sort and group state, but it would not be easy, and information about column sizes and orders is not available there.

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor
0
Wei
Top achievements
Rank 1
answered on 26 Nov 2019, 07:05 PM
Thanks for the answer, I think we will wait for Telerik team to expose the proper API for column setting read and apply to implement this function in our project. 
Tags
Grid
Asked by
Wei
Top achievements
Rank 1
Answers by
Wei
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or