jqGrid - setting caption dynamically

前端 未结 1 873
余生分开走
余生分开走 2021-01-05 00:33

I have the caption parameter set in the jqGrid definition. I want to know if there\'s a way to set it dynamically depending on the class attribute

相关标签:
1条回答
  • 2021-01-05 01:17

    You can use setCaption method to set new caption on the grid:

    var $grid = $('#myjqgrid');
    $grid.jqGrid('setCaption', 'newCaption');
    

    If you need to set the caption depend on the class of the <table> element the code can be like the following

    if ($grid.hasClass('edit')) {
        $grid.jqGrid('setCaption', 'Edit Caption');
    } else if ($grid.hasClass('vew')) {
        $grid.jqGrid('setCaption', 'View Caption');
    } else {
        $grid.jqGrid('setCaption', 'Default Caption');
    }
    

    The only thing which you can't do with respect of setCaption method is to remove (to hide) the caption: the results which you have if you created grid without caption parameter (or with caption: ""). To remove (to hide) the caption you can do

    $(">div.ui-jqgrid-titlebar", $grid.closest('div.ui-jqgrid-view')).hide();
    

    or

    $($grid[0].grid.cDiv).hide();
    

    (see the answer for details).

    0 讨论(0)
提交回复
热议问题