这是我第一次使用JQgrid。我已成功将数据加载到网格,但我的filterToolbar无效。这是我的观点
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<title>jqGrid for ASP.NET MVC - Demo</title>
<!-- The jQuery UI theme that will be used by the grid -->
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.0/themes/redmond/jquery-ui.css" />
<!-- The Css UI theme extension of jqGrid -->
<link rel="stylesheet" type="text/css" href="../../Content/themes/ui.jqgrid.css" />
<!-- jQuery library is a prerequisite for jqGrid -->
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
<!-- language pack - MUST be included before the jqGrid javascript -->
<script type="text/javascript" src="../../Scripts/trirand/i18n/grid.locale-en.js"></script>
<!-- the jqGrid javascript runtime -->
<script type="text/javascript" src="../../Scripts/trirand/jquery.jqGrid.min.js"></script>
<script type="text/javascript">
var myGrid = $('#list');
$(function () {
$("#list").jqGrid({
url: '/JqGridClients/DynamicGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['ClientID', 'Address', 'Company', 'Name'],
colModel: [
{ name: 'ClientID', index: 'ClientID', search: false, width: 60, align: 'left' },
{ name: 'Address', index: 'Address', search: true, sortable: true, align: 'left' },
{ name: 'Company', index: 'Company', search: true, align: 'left', stype: 'select' },
{ name: 'Name', index: 'Name', search: true, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']}}],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'ClientID',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'Clients',
}).navGrid('#pager', { search: true, edit: false, add: false, del: false, searchtext: "Search" });
$("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: 'cn' });
});
</script>
<h2>Index</h2>
<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</asp:Content>
答案 0 :(得分:4)
您正确使用filterToolbar
。你写的只是“我的filterToolbar无法正常工作”,没有任何细节。我想你没有在服务器端实现过滤。
如果用户在过滤器工具栏中输入过滤器,则新请求将发送到服务器('/JqGridClients/DynamicGridData/'
)。选项filter
具有the documentation中描述的格式。请查看the answer或another one以获取代码示例。
如果您需要显示的网格中的行数不是很大(例如,少于1000行),那么您可以通过使用客户端分页和过滤来简化代码。您只需进行以下更改:
loadonce: true
选项您还应该查看您使用的jqGrid选项。例如
imgpath
选项,因为jqGgrid 3.5(当前版本为4.4.5)deprecated。gridview: true
来改善效果pager: jQuery('#pager')
替换为pager: '#pager'
,因为jqGrid需要 string 作为jqGrid的参数。<table>
和<div>
缩减为<table id="list" ></table><div id="pager"></div>
。所有其他属性(包括class
)均已弃用,并且未在过去3年发布的jqGrid版本中使用。答案 1 :(得分:0)
<script type="text/javascript">
var myGrid = $('#list');
$(function () {
$("#list").jqGrid({
url: '/JqGridClients/DynamicGridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['ClientID', 'Address', 'Company', 'Name'],
colModel: [
{ name: 'ClientID', index: 'ClientID', search: false, width: 60, align: 'left' },
{ name: 'Address', index: 'Address', search: true, sortable: true, align: 'left' },
{ name: 'Company', index: 'Company', search: true, align: 'left', stype: 'select' },
{ name: 'Name', index: 'Name', search: true, sortable: true, align: 'left', searchoptions: { sopt: ['cn' ,'eq', 'ne']}}],
pager: jQuery('#pager'),
rowNum: 10,
width: '100%',
height: '100%',
rowList: [5, 10, 20, 50],
sortname: 'ClientID',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
loadonce: true,
caption: 'Clients',
}).navGrid('#pager', { search: true, edit: false, add: false, del: false, searchtext: "Search" });
$("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: 'cn' });
$("#list").setGridParam({data: results.rows, localReader: reader}).trigger('reloadGrid');
});
</script>
我对脚本做了一些更改,现在工作正常。