jqGrid datatype配置为function

jqGrid datatype配置为function

  设置为function实际并不是定义数据类型,而是如何处理从服务器返回的数据(可能未xml或者json)。 配置的方法需要(或者可以)调用addXMLData, addJSONData或者addRowData方法当接收到数据时。如果需要分页,可以在此调用 jqGrid实例名称setGridParam({lastpage: your_number}) 定义页数。
 

  示例

datatype : function(postdata) {
// do something here
}
  配置的方法有一个唯一参数,包含get/post到服务器的数据(JSON对象,为jqGrid配置中的postData配置内容),postData对象和jQuery ajax方法中的data配置一样

  下面为一个datatype设置为function的详细示例
//...
jQuery(document).ready(function(){ 
  jQuery("#list").jqGrid({
    datatype: function(postdata) {
        jQuery.ajax({
           url: 'example.php',
           data:postdata,
           dataType:"xml",
           complete: function(xmldata,stat){
              if(stat=="success") {
                 var thegrid = jQuery("#list")[0];
                 thegrid.addXmlData(xmldata.responseXML);
              }
           }
        });
    },
    colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
    colModel :[ 
      {name:'invid', index:'invid', width:55}, 
      {name:'invdate', index:'invdate', width:90}, 
      {name:'amount', index:'amount', width:80, align:'right'}, 
      {name:'tax', index:'tax', width:80, align:'right'}, 
      {name:'total', index:'total', width:80, align:'right'}, 
      {name:'note', index:'note', width:150, sortable:false} 
    ],
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'invid',
    sortorder: 'desc',
    viewrecords: true,
    caption: 'My first grid'
  }); 
}); 
//...

来源:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data

加支付宝好友偷能量挖...


原创文章,转载请注明出处:jqGrid datatype配置为function

评论(0)Web开发网
阅读(966)喜欢(0)jqGrid中文API