Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

javascript - Load jqgrid structure from server, not only data

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...