jQWidgets Forums
jQuery UI Widgets › Forums › Grid › question regarding "rendered" callback
This topic contains 2 replies, has 2 voices, and was last updated by stephan 11 years, 5 months ago.
-
Author
-
Hi,
I am now testing to enable selectionmode “checkbox” for one of my grids and noticed somethign strange regarding the “rendered” callback. I have defined a “rendered” callback function and within this function I up to now assumed that “this” points to the actual jqxGrid object. This has worked quite well up to now independant of the complexity and other parameters of my grid. The strange thing is: by setting the grid property “selectionmode” to “checkbox” I observe that the grids (!) “rendered” callback now gets called for the checkbox column, and in this call “this” points to the checkbox column object (instead of the grid). Is this intentional or a mistake ?
Regards,
StephanHi Stephan,
I am not sure why you use “this” at all in that function and why you take into account that it should be something specific. That is not documented and “this” relates to the function’s context which could be anything. If you need access to the Grid’s object, select it with jQuery and call its property/method through the normal and documented way.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Well, the reason probably boils down to convenience: I considered using “this” the fastest and easiest way to achieve what I wanted to do: I wanted to add an extra CSS class to all rows. Here’s my rendered event (including a fix for the potentially incorrect ‘this’):
rendered : function () { if (this.host != null) { var rows = this.host.find('div[role=row]'); rows.addClass('my-extra-css-class'); } },
I did not find an easy alternative because after calling the jqxGrid() constructor the rows aren’t there yet.
As you can see I found a simple fix for the “this” problem. I was just wondering why a checkbox column causes an extra call to the grids overall rendered event(with the column as context).
At this point there is a certain discrepancy between my expectation and what actually happens: I would expect that creating a grid would cause “rendered” to be called once at the appropriate time. Same as “initialize” gets raised once during creation and “ready” gets called once during creation. Yet I observe that “rendered” gets called multiple times, for my current grid setup it gets called 3 times.
Regards,
Stephan -
AuthorPosts
You must be logged in to reply to this topic.