jQWidgets Forums

jQuery UI Widgets Forums Grid Cells Rendering within a loop

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  Peter Stoev 11 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Cells Rendering within a loop #50004

    zbrady
    Participant

    I am trying to apply a unique cellsrenderer to each column via a loop. However, the j in rowData.Line[j] does not hold the value. Is there a way to pass the value of j to the cellsrenderer function?

    for(var j = 0; j < columnArray.length; j++){
    
                var cellsrenderer = function (indexRow, column, cellValue, defaultHtml, colSettings, rowData) {
                    return '<div style="text-align: center; margin-top: 5px;">' + rowData.Line[j] + '</div>';
                }
                $('#jqxgrid').jqxGrid('setcolumnproperty', columnArray[j] ,'cellsrenderer', cellsrenderer);
                
            }
    Cells Rendering within a loop #50005

    Peter Stoev
    Keymaster

    Hi zbrady,

    “setcolumnproperty” expects a datafield as first parameter. The cellsrenderer definition according to me is incorrect to. The method should depend only on the parameters which the Grid passes to it.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Cells Rendering within a loop #50007

    zbrady
    Participant

    I don’t think I asked my question correctly..

    This code works, if I hard code the zero into rowData.Line instead of putting j. However, I am looking for a way to pass in j to rowData.Line .

    for(var j = 0; j < columnArray.length; j++){
      
         var cellsrenderer = function (indexRow, column, cellValue, defaultHtml, colSettings, rowData) {
             return '<div style="text-align: center; margin-top: 5px; ">' + rowData.Line[0] '</div>';
         }
         $('#jqxgrid').jqxGrid('setcolumnproperty', columnArray[j] ,'cellsrenderer', cellsrenderer);
                
     }'
    Cells Rendering within a loop #50009

    Peter Stoev
    Keymaster

    Hi zbrady,

    That’s what I meant. You can’t pass custom variables to a function called internally by jqxGrid.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.