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

Calling kendoGrid dataSource.read() removes added class to current row

6 Answers 1088 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bjoern
Top achievements
Rank 1
Iron
Bjoern asked on 22 Apr 2021, 02:04 PM

I have added a custom class to each td in a kendoGrid, to display a different color in cells that are readonly.

But when I run this: $("myGrid").data("kendoGrid").refresh();

it removes the class from the current row.

Is there a way to prevent this from happening?

6 Answers, 1 is accepted

Sort by
0
Bjoern
Top achievements
Rank 1
Iron
answered on 26 Apr 2021, 07:52 PM

I must correct my initial post.

In the .dataBound-event I run .addClass to each td in the grid, to mark certain cells with different colors.

 

In the dataSource change-event, I run this code after changing the sortorder:

var ds = $("myGrid").data("kendoGrid").dataSource;
ds.read();

The .Databound-event get triggered after ds.read(), but the css-classes is removed after the Databound-event.

Apparently some events gets triggered after the Databound-event that removes the classes.

0
Tsvetomir
Telerik team
answered on 27 Apr 2021, 07:51 AM

Hi Bjoern,

In general, the dataBound event is the last event that is triggered after the grid has been rendered. Therefore, there are no consequent events that are forcing the grid to repaint without calling the dataBound event. 

I am not completely sure why the logic for calling the read() method inside the change event of the data source is needed. Could you share more information about this functionality? By design, the grid will perform the AJAX requests when the serverSorting is set to true. Otherwise, it would sort on the client-side. 

It would be very helpful if you could share the exact code snippets that you have used in your application so that I can use them and replicate the scenario locally. This way, I would have the chance to debug it and get back to you with the respective suggestions.

Looking forward to your reply.

 

Kind regards,
Tsvetomir
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Bjoern
Top achievements
Rank 1
Iron
answered on 27 Apr 2021, 08:44 AM | edited on 27 Apr 2021, 11:59 AM

Thank you for your reply.

I have made a simple example here. https://dojo.telerik.com/@bjoler/UQaHaceL

What I want is to change the SortOrder directly in the grid, and make the grid repaint itself accordingly.

So when I change the last row's SortOrder value from 12 to 1, that row should be the first row.

 

0
Tsvetomir
Telerik team
answered on 28 Apr 2021, 11:29 AM

Hi Bjoern,

In general, the sort is being applied only when the update in the data source has been successful. If you would like to repaint the grid after an update, you could set the autoSync property to true.

Check out the modified version here:

https://dojo.telerik.com/OseyavOs

Let me know if there is anything else I can help with.

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Bjoern
Top achievements
Rank 1
Iron
commented on 03 May 2021, 08:55 AM

Please see my updated version below
0
Bjoern
Top achievements
Rank 1
Iron
answered on 28 Apr 2021, 06:40 PM

Thanks again for the reply.

I have an updated versjon here:

https://dojo.telerik.com/@bjoler/AmoxOsaT

 

I've added styling to the last column. See what happens with the colour when changing the value in the last row from 12 to 1.

0
Accepted
Tsvetomir
Telerik team
answered on 03 May 2021, 09:58 AM

Hi Bjoern,

Thank you for the updated Dojo. Indeed, we should wrap the logic inside the dataBound event handler inside a setTimeout() function. This is needed in order to allow the grid to completely update its row and only then apply the styling. Please take a look at the following updated sample:

https://dojo.telerik.com/usilujuK

I hope you find this helpful.

 

Kind regards,
Tsvetomir
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Bjoern
Top achievements
Rank 1
Iron
Answers by
Bjoern
Top achievements
Rank 1
Iron
Tsvetomir
Telerik team
Share this question
or