This is my first time working with Kendo UI. I have a Kendo UI grid with child nodes. I want to retain the expanded rows after databinding. Right now its getting collapsed after a row is added in the child
I have tried suggestion from here
dataBound: function() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
But this expands the first row only.
How to retain rows? What am I missing?
Solution for Retaining Last Expanding row in the parent grid after records added in the child grid get refreshed.
After a lot of playing around with your code example in CodePen, I believe I've come up with an elegant solution that works.
Having worked with Kendo UI for over three years, I've become pretty familiar with some of its inner workings. As such, I'm going to take advantage of one of these - the
data-uid
attribute. Kendo UI puts these on all<tr>
elements in its grid. I chose this attribute because I know that when we callgrid.expandRow()
we're going to need to fashion a valid jQuery selector to pass in as a parameter. This eliminates the need for us to add our own attributes or classes and the code to handle them.First, we need to define a variable to hold our row reference. We'll call it
expandedRowUid
. To set its value, we hook into thedetailExpand
event of the grid. So, when the user expands a row, we store itsdata-uid
number.Then, whenever a change is made that causes the master grid to re-bind to its data, we hook into the
dataBound
event of the grid and re-expand the row that has adata-uid
equal to the one stored inexpandedRowUid
.Here is the working CodePen example.
NOTE: This will only re-expand the last row that was expanded before the data bind is triggered. So, if you expand rows 4, 5, and 2 in that order, and then trigger a data bind, only row 2 will be re-expanded. You can obviously extend this functionality to handle use cases like that though.
And then on databound
Functions required:
Hope this helps ... took me a while to figure it out...