Select row in server side/ codebehind

Hello support,

I have implemented  custom state persistence on the grid(search string, order, filtering, selected row). Needed data are stored clientside in a cookie and used serverside. I can successfully apply all except the selected row.

To be able to select the correct row i need to traverse all rows(row might have been deleted by another user) and the problem is i cannot find the rows in the grid object(i am using an offline DataManager with a JsonAdaptor).

syncfusion1.png

I will not be using the native persistence syncfusion provides because i need full control over it(action wise and time wise) and it was also breaking the appearance of the grid for some reason.

Here are the important parts of the code:

aspx:

syncfusion2.png

cs: (this part of code is before DataBind())

syncfusion3.png

I have also tried before to apply persistence data on client side but i would like to avoid that for 1) UX reasons(speed) 2)Could not apply persistence on DataBound event as stated in many answers. I was able to use onActionComplete event but still faced problems with selectedRow.

So, i would like to get an array of objects/rows (after applying search, sort and filter) so i can correctly try to find the index of the row then calculate page number and at last select row.



4 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 9, 2021 03:39 PM UTC

Hi Stavros, 

Greetings from Syncfusion Support. 

Query#:- i would like to get an array of objects/rows (after applying search, sort and filter) so i can correctly try to find the index of the row then calculate page number and at last select row. 
 
We have already discussed about “how to get the selectedrows in code-behind” in our Syncfusion knowledge Base. So please refer to the below KB link:- 
 
Also you can get the array of objects after performing these actions using getCurrentViewRecords method of the Grid. Refer to the API link:- 
Note:- It will return the current page records alone when we enable Paging. 

If your requirement is different from above, please share more details to proceed further. 

Regards, 
Farveen sulthana T 



SN Stavros Nissopoulos replied to Farveen Sulthana Thameeztheen Basha December 10, 2021 04:29 PM UTC

Hello,

My requirements are different.

I want to select a row in code behind(the one that is saved in a cookie). In order to do that i need to traverse all the grid rows to make sure the row is still there(could have been deleted by another user). So i am looking for a property in the Grid that holds all the rows ( so the getCurrentViewRecords method is not gonna work).

This is how i am doing it now in the client side and i want to run this logic on the serverside:

syncfusion4.png

Please read again my initial post, same info are there about my requirements.



PS Pon Selva Jeganathan Syncfusion Team December 13, 2021 01:59 PM UTC

Hi Stavros, 
 

We are working on this (select a row in code behind.) with high priority and we will update with further details by 15th December 2021.

 
Until then we value your patience. 
 
Regards,   
Pon selva    





FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 15, 2021 04:58 PM UTC

Hi Stavros, 

We appreciate your patience. 

From your provided code, we can calculate the Selected Row using PageSize from traversing over all the rows at server side as like provided in the KB or we can get the value from using the PrimaryKey value and select it from server end. 

[aspx.cs] 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        var datasource = OrderRepository.GetAllRecords().ToList(); 
        this.FlatGrid.DataSource = datasource; 
        int rowindex = datasource.FindIndex(a => a.OrderID == 10307) % 12; 
        int currentPage = datasource.FindIndex(a => a.OrderID == 10307) / 12 + 1; 
        this.FlatGrid.SelectedRowIndex = rowindex; 
        this.FlatGrid.PageSettings.CurrentPage = currentPage; 
       this.FlatGrid.DataBind(); 
    } 

But cannot access the local Storage value at server end. We need to pass the local  Storage values from client end through AJAX post and perform your required actions at server end  which can also be discussed in the KB:- 

If your requirement is different from above or misinterpreted your query please share more details like Video Demo to proceed further. 

Regards, 
Farveen sulthana T 


Loader.
Up arrow icon