Load jqgrid structure from server, not only data

前端 未结 2 2008
滥情空心
滥情空心 2020-12-06 23:27

Is it possible to load from server via ajax JQGrid structure(columns) together with data ? If possible, could you please show an example ?

2条回答
  •  情书的邮戳
    2020-12-06 23:48

    There's no reason why not, you just ned to do things (asynchronously) in the correct order, something like this (forgive the psuedo code)

    var jqGridOptions = {
       /*  various options here */
    }
    
    $.ajax({
       url: jqGridStructureUrl
    }).success(function(jqGridColumns){
    
    
        // Add the col model to the other options    
        jqGridOptions.colModel = jqGridColumns.colModel
        jqGridOptions.colNames = jqGridColumns.colNames
    
        // set up the jqGrid
        $j("#gridId").jqGrid(jqGridOptions)
    
    })
    

    This will get you part of the way there. I guess you'll also be wanting to load Data via Ajax in which case you can set the "Data" option on the jqGrid settings to a callback function (this is not very well documented) - OR you could fire off TWO ajax calls, one for data and one for structure and then when they're BOTH back munge the two together and instantiate your grid object

提交回复
热议问题