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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • question regarding "rendered" callback #46425

    stephan
    Participant

    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,
    Stephan

    question regarding "rendered" callback #46430

    Peter Stoev
    Keymaster

    Hi 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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    question regarding "rendered" callback #46456

    stephan
    Participant

    Hi 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

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.