使用jquery.jqgrid.js无法打开jqgrid搜索工具栏
在尝试了几种方法之后,我尝试用jquery.jqgrid.js添加搜索栏。该方法是唯一没有给我错误的方法,但也没有显示我的搜索工具栏,有人能看看我是否遗漏了什么吗使用jquery.jqgrid.js无法打开jqgrid搜索工具栏,jqgrid,Jqgrid,在尝试了几种方法之后,我尝试用jquery.jqgrid.js添加搜索栏。该方法是唯一没有给我错误的方法,但也没有显示我的搜索工具栏,有人能看看我是否遗漏了什么吗 jQuery(document).ready(function() { jQuery("#list").jqGrid({ url: '/Home/DynamicGridData/', datatype: 'json', mtype: 'POST', colName
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '/Home/DynamicGridData/',
datatype: 'json',
mtype: 'POST',
colNames: ['Edit', 'AlertId', 'Policy', 'PolicyRule', 'Alert Status',
'Alert Code', 'Message', 'Category'],
colModel: [
{ name: 'Edit', edittype: 'select', formatter: 'showlink' },
{ name: 'AlertId', index: 'AlertId', sortable: true, sorttype: 'int',
autoFit: true, align: 'left', hidden: true },
{ name: 'Policy', index: 'Policy.Name', sortable: true, sorttype: 'text',
autoFit: true, searchoptions: { sopt: ['eq', 'ne', 'cn'] },
align: 'left' },
{ name: 'Policy Rule', index: 'PolicyRule', sortable: true,
sorttype: 'text', autoFit: true, sorttype: 'text',
searchoptions: { sopt: ['eq', 'ne', 'cn'] }, align: 'left' },
{ name: 'Alert Status', index: 'AlertStatus.status', sortable: true,
sorttype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn'] },
autoFit: true, align: 'left' },
{ name: 'Alert Code', index: 'Code', sortable: true, sorttype: 'text',
align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn'] },
autoFit: true },
{ name: 'Message', index: 'Message', sortable: true, sorttype: 'text',
align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn'] },
autoFit: true },
{ name: 'Category', index: 'Category.name', sortable: true,
sorttype: 'text', align: 'left', autoFit: true,
searchoptions: { sopt: ['eq', 'ne', 'cn'] }}],
pager: $("#pager"),
rowNum: 10,
rowList: [10, 60, 100],
scroll: true,
sortname: 'AlertId',
sortorder: 'asc',
viewrecords: true,
imgpath: '/scripts/themes/basic/images',
caption: 'my name',
gridComplete: function() {
var objRows = $("#list tr");
var objHeader = $("#list.jqgfirstrow td");
if (objRows.length > 1) {
var objFirstRowColumns = $(objRows[1]).children("td");
for (i = 0; i < objFirstRowColumns.length; i++) {
$(objFirstRowColumns[i]).css("width",
$(objHeader[i]).css("width"));
}
}
}
});
});
$("#list").jqGrid('navGrid','#pager',
{edit:true,add:true,del:true,search:true,refresh:true});
$("#list").jqGrid('navButtonAdd',"#pager",
{caption:"Toggle",title:"Toggle Search Toolbar",
buttonicon :'ui-icon-pin-s',
onClickButton:function() {
$("#list")[0].toggleToolbar()
} });
$("#list").jqGrid('navButtonAdd',"#pager",
{ caption: "Clear", title: "Clear Search",
buttonicon :'ui-icon-refresh',
onClickButton:function(){
$("#list")[0].clearToolbar()
} });
jQuery("#list").jqGrid('filterToolbar');
jQuery(文档).ready(函数(){
jQuery(“#list”).jqGrid({
url:“/Home/DynamicGridData/”,
数据类型:“json”,
mtype:“POST”,
colNames:['Edit'、'AlertId'、'Policy'、'PolicyRule'、'Alert Status',
“警报代码”、“消息”、“类别”],
colModel:[
{name:'Edit',edittype:'select',格式化程序:'showlink'},
{name:'AlertId',index:'AlertId',sortable:true,sorttype:'int',
自动拟合:真,对齐:“左”,隐藏:真},
{name:'Policy',index:'Policy.name',sortable:true,sorttype:'text',
自动拟合:true,搜索选项:{sopt:['eq','ne','cn']},
对齐:'左'},
{name:'Policy Rule',index:'Policy Rule',sortable:true,
sorttype:'text',自动拟合:true,sorttype:'text',
搜索选项:{sopt:['eq','ne','cn']},对齐:'left'},
{name:'Alert Status',index:'AlertStatus.Status',sortable:true,
sorttype:'文本',搜索选项:{sopt:['eq','ne','cn']},
自动拟合:true,对齐:'左'},
{name:'Alert Code',index:'Code',sortable:true,sorttype:'text',
对齐:'left',搜索选项:{sopt:['eq','ne','cn']},
autoFit:true},
{name:'Message',index:'Message',sortable:true,sorttype:'text',
对齐:'left',搜索选项:{sopt:['eq','ne','cn']},
autoFit:true},
{name:'Category',index:'Category.name',sortable:true,
sorttype:'text',align:'left',autoFit:true,
搜索选项:{sopt:['eq','ne','cn']}},
传呼机:$(“#传呼机”),
rowNum:10,
行列表:[10,60,100],
卷轴:没错,
sortname:'AlertId',
排序器:“asc”,
viewrecords:是的,
imgpath:“/scripts/themes/basic/images”,
描述:“我的名字”,
gridComplete:函数(){
var objRows=$(“#list tr”);
var objHeader=$(“#list.jqgfirstrow td”);
如果(objRows.length>1){
var objFirstRowColumns=$(objRows[1]).children(“td”);
对于(i=0;i
改进代码格式后,您可以看到您的主要错误:调用navGrid
、navbuttonad
和filterToolbar
在jQuery(document)的外部。如果将其移动到jQuery(document).ready
中,您将立即看到搜索工具栏:请参阅
您的代码还有其他小问题:
变量i
内部gridComplete
应声明为局部变量,而不是全局变量
您应该删除不推荐使用的参数imgpath
您可以使用许多带有默认值的colModel
参数选项,如sortable:true
,sorttype:'text'
,align:'left'
等。这只会使代码变得更长、更慢、更难阅读。我建议您查看哪个描述了colModel
参数,并删除默认属性
如果使用datatype:'json'
而不使用loadonce:true,则使用的sorttype
属性将不起作用。因此,您应该决定使用基于服务器的排序、分页和筛选/搜索,最好删除案例中的sorttype
属性,或者使用loadonce:true
,但在向服务器发出第一个请求时,应立即加载网格包含
没有autoFit
列属性