【问题标题】:Jqgrid and navgrid search buttonJqgrid 和 navgrid 搜索按钮
【发布时间】:2011-12-14 09:23:03
【问题描述】:

我有一个用 jqGrid 创建的表(用 JSON POST 数据生成)。导航效果很好。 我设置了显示搜索按钮的选项。

当我点击显示的选项时……但没有进行任何研究……

这项研究是在数组元素中使用 Javascript 完成的,还是指定了在 Ajax 中搜索的 URL?

这是我的代码。

<div id="liste">
<div id="messagebox"></div>
<div id="filter"></div>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</div>

<script type="text/javascript">     
$(document).ready(function(){

   $("#list").jqGrid({
        url:'/admin/statistique/getjson/',
        datatype: 'json',
        mtype: 'POST',
        colNames:['','Nom','Visites Totales', 'Visites Uniques','Contact'],
        colModel:[
            {name:'edition',index:'edition', sortable:false,editable: false,width:15, align:"center"},
            {name:'etablissement_nomAMarrakech',index:'etablissement_nomAMarrakech', sortable:true, editable: false,width:150, align:"center"},
            {name:'',index:'', sortable:false, editable: false,width:200, align:"center"},
            {name:'',index:'', sortable:false, editable: false,width:200, align:"center"},
            {name:'',index:'', sortable:false, editable: false,width:240, align:"center"}
        ],
        pager: '#pager',
        rowNum:10,
        rowList:[10,25,50,100,300],
        sortname: 'etablissement_nomAMarrakech',
        viewrecords: true,
        autowidth: true,
        rownumbers: false,
        gridview : true,
        sortorder: "desc",
        caption:"Aperçu des statistiques"
    });

    jQuery("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:false,refresh:false});         
});

</script>

这是一个屏幕

如您所见,当我提交表单时,JQGrid 写“正在加载...”但没有检查任何行...

此致,

【问题讨论】:

    标签: jquery json jqgrid


    【解决方案1】:

    你使用

    name:'',index:''
    

    在网格中定义三列。这是错误的。您可以将其与您尝试使用名称为 '' 的三个属性声明类的代码进行比较。

    name 属性是强制性的。它必须是唯一的,不能等于保留名称('rn'、'cb' 和 'subgrid')中的一个,并且不应包含 jQuery 选择器中使用的任何元字符,如 '.'、' ' 等(见here)。

    此外,如果您使用datatype: 'json' 而不使用loadonce: true,则服务器将负责数据过滤。在搜索请求时,将发送对服务器的新请求,其中包含额外的 &amp;searchField=edition&amp;searchString=Spa&amp;searchOper=cn 等参数。服务器应将过滤后的数据返回给 jqGrid。

    【讨论】:

    • 很好的帮助和资源。非常感谢你。现在我知道有像 searchString 这样的参数...我测试并且它有效。