试图了解jqgrid的jqgrid.如何更改AJAX调用的URL?

joh*_*nny 14 jquery jqgrid

我从教程中完成了所有工作,用我的数据替换它,但这是一个硬编码的情况.例如,在我正在工作的教程中,我有:

jQuery(document).ready(function(){ 
  jQuery("#list").jqGrid({
    url:'http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['ProductID','title', 'description','price','tax','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: jQuery('#pager'),
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'title',
    sortorder: "desc",
    viewrecords: true,
    imgpath: 'http://127.0.0.1/products/public/themes/basic/images',
    caption: 'Product List'
  }); 
}); 
Run Code Online (Sandbox Code Playgroud)

但是网址被硬编码以提取数据.该教程有:

jQuery(document).ready(function(){ 
  jQuery("#list").jqGrid({
    url:'example.php',
    datatype: 'xml',
    mtype: 'GET',
    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: jQuery('#pager'),
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'id',
    sortorder: "desc",
    viewrecords: true,
    imgpath: 'themes/basic/images',
    caption: 'My first grid'
  }); 
}); 
Run Code Online (Sandbox Code Playgroud)

显然,我的查询字符串中的数据会发生变化,我不会总是想要相同的网址:http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc

而且,使用example.php的教程需要查询字符串变量,因此它可以获得正确的数据,但它们从未显示我能找到的部分.那么如何更改查询字符串?如何动态发送项目?此外,由于硬编码网址,寻呼机按钮会发送这样的内容:

http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc?page=2&rows=10&sidx=productname&sord=desc&nd=1248988261293&_search=false

我怎么能有一个像/ test /正确的变量的网址?如何更改查询字符串?

感谢您的任何帮助.我希望它不是太明显.我找到了setGridParam({url:newvalue}),但不明白如何使用它.

这是文档.本教程是第一部分,顶部.

编辑:谢谢你的下面.我试图看看他们如何使用example.php在他们的教程中使用setGridParam.他们只是有example.php,我无法看到他们如何从html页面到example.php页面获取查询字符串变量.setGridParam可能是实现此目的的正确方法,但它不是示例中的位置,因此我无法弄清楚它们是如何传递初始查询字符串变量的.

我知道我可以这样做:

    function gridSearch()
    {
        $("#list").setGridParam(
            {

                  url:"http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc",
                page:1
            }
            ).trigger("reloadGrid");//Reload grid trigger
        return false
    }

<input id="sData" class="EditButton" type="submit" value="Search" onClick="return gridSearch()"/>
Run Code Online (Sandbox Code Playgroud)

那将重新加载网格(我测试了它;它的工作原理),但他们是如何首先发送教程中的项目的?如果我不想重新加载按钮但只是传入变量以便最初加载怎么办?

red*_*are 46

After you have created your grid you can build up a url and then specify this and trigger the grid to reload.

jQuery("#list").jqGrid().setGridParam({url : 'newUrl'}).trigger("reloadGrid")
Run Code Online (Sandbox Code Playgroud)

  • 好吧有时你必须从api推断出事物.当它是免费产品时,它们无法在abc中拼出所有内容. (2认同)