<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>曾华水的博客 &#187; jqGrid</title>
	<atom:link href="http://www.mrzeng.com/tag/jqgrid/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mrzeng.com</link>
	<description>NO.1 or Nothing</description>
	<lastBuildDate>Wed, 07 Sep 2011 12:47:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jqGrid进阶教程：3、jqGrid的数据格式化二</title>
		<link>http://www.mrzeng.com/post/jqgrid-formater-2.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-formater-2.html#comments</comments>
		<pubDate>Wed, 06 Oct 2010 07:48:03 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=229</guid>
		<description><![CDATA[jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。 我们接上面的例子 $("#grid_id").jqGrid({ ... colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ], ... }); 此时，我们增加格式化 $("#grid_id").jqGrid({ ... colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}},formatter:function(cellvalue, options, row){ if(cellvalue==1){ return "男"; }else{ return "女"; } } ... ], ... }); 这样操作起来就比较方便。我们也可以把这个方法独立出来，例如：我们在数据库设置的时候常用1来标示“是”，0标示“否”，这时候我们前台展示的时候肯定不能只显示1或者0，于是必须转换，如果比较多字段用到，我们就采用独立出来写一个。 function sexFmatter(cellvalue, options, rowObject){ if(cellvalue==1){ return "男"; }else{ return "女"; } } 在formatter属性后面填写方法名 $("#grid_id").jqGrid({ ... colModel : [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。<br />
我们接上面的例子</p>
<pre class=prettyprint>
$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
</pre>
<p> 此时，我们增加格式化</p>
<pre class=prettyprint>
$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}},formatter:function(cellvalue, options, row){
     if(cellvalue==1){
         return "男";
    }else{
        return "女";
   }
   } ... ],
...
});
</pre>
<p>这样操作起来就比较方便。我们也可以把这个方法独立出来，例如：我们在数据库设置的时候常用1来标示“是”，0标示“否”，这时候我们前台展示的时候肯定不能只显示1或者0，于是必须转换，如果比较多字段用到，我们就采用独立出来写一个。</p>
<pre class=prettyprint>
function sexFmatter(cellvalue, options, rowObject){
         if(cellvalue==1){
         return "男";
    }else{
        return "女";
   }
}
</pre>
<p>在formatter属性后面填写方法名</p>
<pre class=prettyprint>
$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}},formatter: sexFmatter... ],
...
});
</pre>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid_base_study_8-2.html" title="jqGrid基础学习：8jqGrid中在导航条使用按钮">jqGrid基础学习：8jqGrid中在导航条使用按钮</a><br /><small>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。

使用默认的方法
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下

jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edi...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-formater-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid例子文件下载</title>
		<link>http://www.mrzeng.com/post/jqgrid-example-download.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-example-download.html#comments</comments>
		<pubDate>Sat, 25 Sep 2010 07:36:52 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=223</guid>
		<description><![CDATA[最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。 jqGrid 由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2 相关日志jqGrid进阶教程：3、jqGrid的数据格式化二jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。 我们接上面的例子 $("#grid_id").jqGrid({ ... colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ], ... }); ...jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框， 例如 [caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption] 这种问题的原因多半是因为html的标准问题，即其写法为 如果要让样式正常，要采用写法如下 ...jqGrid基础学习：11jqGrid的查询时和后台的交互jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。 单字段 我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下 [caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption] 由此，我们看出单字段查询...jqGrid基础学习：10jqGrid的多字段查询多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。 [caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption] 启用多条件查询的方法，是加上.searchGrid({multipleSearch:true}); 即可。 ...jqGrid基础学习：8jqGrid中在导航条使用按钮jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。 使用默认的方法 系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下 jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{ //这里可以指定edi...]]></description>
			<content:encoded><![CDATA[<p>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。<br />
<a href='http://www.mrzeng.com/wp-content/uploads/2010/09/jqGrid.zip'>jqGrid</a><br />
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid_base_study_8-2.html" title="jqGrid基础学习：8jqGrid中在导航条使用按钮">jqGrid基础学习：8jqGrid中在导航条使用按钮</a><br /><small>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。

使用默认的方法
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下

jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edi...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-example-download.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</title>
		<link>http://www.mrzeng.com/post/jqgrid-css.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-css.html#comments</comments>
		<pubDate>Sun, 01 Aug 2010 07:35:11 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=220</guid>
		<description><![CDATA[jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框， 例如 这种问题的原因多半是因为html的标准问题，即其写法为 &#60;html&#62; &#60;/html&#62;&#60;html&#62; &#60;/html&#62; 如果要让样式正常，要采用写法如下 &#60; !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&#62; &#60;html xmlns="http://www.w3.org/1999/xhtml"&#62; &#60;/html&#62;&#60;html&#62; &#60;/html&#62; 相关日志jqGrid进阶教程：3、jqGrid的数据格式化二jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。 我们接上面的例子 $("#grid_id").jqGrid({ ... colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ], ... }); ...jqGrid例子文件下载最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。 jqGrid 由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...jqGrid基础学习：11jqGrid的查询时和后台的交互jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。 单字段 我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下 [caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption] 由此，我们看出单字段查询...jqGrid基础学习：10jqGrid的多字段查询多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。 [caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption] 启用多条件查询的方法，是加上.searchGrid({multipleSearch:true}); 即可。 ...jqGrid基础学习：8jqGrid中在导航条使用按钮jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。 使用默认的方法 系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下 [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，<br />
<span id="more-220"></span><br />
例如<br />
<div id="attachment_407" class="wp-caption alignnone" style="width: 310px"><a href="http://huashui.org/wp-content/uploads/2010/08/QQ截图未命名.jpg"><img src="http://huashui.org/wp-content/uploads/2010/08/QQ截图未命名-300x95.jpg" alt="CSS变样" title="CSS变样" width="300" height="95" class="size-medium wp-image-407" /></a><p class="wp-caption-text">CSS变样</p></div><br />
这种问题的原因多半是因为html的标准问题，即其写法为</p>
<pre class=prettyprint>
&lt;html&gt;
&lt;/html&gt;&lt;html&gt;
&lt;/html&gt;</pre>
<p>如果要让样式正常，要采用写法如下</p>
<pre class=prettyprint>
&lt; !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;/html&gt;&lt;html&gt;
&lt;/html&gt;</pre>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid_base_study_8-2.html" title="jqGrid基础学习：8jqGrid中在导航条使用按钮">jqGrid基础学习：8jqGrid中在导航条使用按钮</a><br /><small>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。

使用默认的方法
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下

jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edi...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-css.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：11jqGrid的查询时和后台的交互</title>
		<link>http://www.mrzeng.com/post/jqgrid-base-study-11.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-base-study-11.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 08:27:20 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=213</guid>
		<description><![CDATA[jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。 单字段 我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下 由此，我们看出单字段查询，jqGrid向服务器传递的参数是searchField、searchString、searchOper这三个参数。 searchField代表要查询的字段，searchString是查询的内容，searchOper是操作，后台获取到的searchOper的值，对应的是&#8217;eq&#8217;,'ne&#8217;,'lt&#8217;,'le&#8217;,'gt&#8217;,'ge&#8217;,'bw&#8217;,'bn&#8217;,'in&#8217;,'ni&#8217;,'ew&#8217;,'en&#8217;,'cn&#8217;,'nc&#8217;，这些可以再jqGrid设置那些使用，那些不使用。 多字段查询 使用同样的方法，我们可以发现，多字段查询，jqGrid向后台传递的参数为一个json字符串。 因此，取得这个数据需要进行对json数据进行解析。 同时，我们注意到。不管是单字段查询还是多字段查询，如果前台执行了查询，都会向后台传递一个_search参数，来指明后台是否启用搜索。 其他的就不废话了，直接上源码。 新建一个规则的类 public class SearchRule { private String field; //查询字段 private String op; //查询操作 private String data; //选择的查询值 public String getField() { return field; } public void setField(String field) { this.field = field; } public String getOp() { return op; } public void setOp(String op) { [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。</p>
<p><span id="more-213"></span><br />
<strong>单字段</strong><br />
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下<br />
<div id="attachment_382" class="wp-caption alignnone" style="width: 310px"><a href="http://huashui.org/wp-content/uploads/2010/03/2010-3-3-2.jpg"><img src="http://huashui.org/wp-content/uploads/2010/03/2010-3-3-2-300x169.jpg" alt="单字段同后台交互" title="2010-3-3-2" width="300" height="169" class="size-medium wp-image-382" /></a><p class="wp-caption-text">单字段同后台交互</p></div><br />
由此，我们看出单字段查询，jqGrid向服务器传递的参数是searchField、searchString、searchOper这三个参数。<br />
searchField代表要查询的字段，searchString是查询的内容，searchOper是操作，后台获取到的searchOper的值，对应的是&#8217;eq&#8217;,'ne&#8217;,'lt&#8217;,'le&#8217;,'gt&#8217;,'ge&#8217;,'bw&#8217;,'bn&#8217;,'in&#8217;,'ni&#8217;,'ew&#8217;,'en&#8217;,'cn&#8217;,'nc&#8217;，这些可以再jqGrid设置那些使用，那些不使用。</p>
<p><strong>多字段查询</strong><br />
使用同样的方法，我们可以发现，多字段查询，jqGrid向后台传递的参数为一个json字符串。<br />
<div id="attachment_383" class="wp-caption alignnone" style="width: 310px"><a href="http://huashui.org/wp-content/uploads/2010/03/2010-3-3-3.jpg"><img src="http://huashui.org/wp-content/uploads/2010/03/2010-3-3-3-300x156.jpg" alt="jqGrid多字段查询" title="2010-3-3-3" width="300" height="156" class="size-medium wp-image-383" /></a><p class="wp-caption-text">jqGrid多字段查询</p></div><br />
因此，取得这个数据需要进行对json数据进行解析。</p>
<p>同时，我们注意到。不管是单字段查询还是多字段查询，如果前台执行了查询，都会向后台传递一个_search参数，来指明后台是否启用搜索。</p>
<p>其他的就不废话了，直接上源码。<br />
新建一个规则的类</p>
<pre class=prettyprint>
public class SearchRule {
	private String field;   //查询字段
    private String op;      //查询操作
    private String data;    //选择的查询值
	public String getField() {
		return field;
	}
	public void setField(String field) {
		this.field = field;
	}
	public String getOp() {
		return op;
	}
	public void setOp(String op) {
		this.op = op;
	}
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = data;
	}
}
</pre>
<p>新建一个过滤的类</p>
<pre class=prettyprint>
public class FilterSearch {
	private String groupOp; //多字段查询时分组类型，主要是AND或者OR   

	private List&lt;searchrule&gt; rules; //多字段查询时候，查询条件的集合 

	public String getGroupOp() {
		return groupOp;
	}
	public void setGroupOp(String groupOp) {
		this.groupOp = groupOp;
	}
	public List&lt;/searchrule&gt;&lt;searchrule&gt; getRules() {
		return rules;
	}
	public void setRules(List&lt;/searchrule&gt;&lt;searchrule&gt; rules) {
		this.rules = rules;
	}

}

&lt;/searchrule&gt;</pre>
<p>查询的工具类</p>
<pre class=prettyprint>
public class JqGridHandler {

	private HttpServletRequest request = null;

	private String _search = "false";
	private String searchField;
	private String searchOper;
	private String searchString;
	private String filters;
	private String sidx = "1";
	private String sord = "desc";

	// 存储总体的search
	FilterSearch filterSearch = null;

	public JqGridHandler() {

	}

	public JqGridHandler(HttpServletRequest request) {
		this.request = request;

	}

	public String getWheres(String prefix, boolean isWhere) {
		conditions();
		if(tranToSQL(prefix).trim().equals("")){
			return "";
		}
		if (!isWhere) {
			return new StringBuilder(" where ").append(tranToSQL(prefix))
					.toString();
		}
		return new StringBuilder(" and ").append(tranToSQL(prefix)).toString();
	}

	public String getOrders(String prefix, boolean isOrder) {
		init();
		StringBuilder sb = new StringBuilder();
		if (isOrder) {
			if (null != prefix) {
				sb.append(prefix).append(".");
			}

		} else {
			sb.append(" order by ");
			if (null != prefix) {
				sb.append(prefix).append(".");
			}
		}
		return sb.append(doTables(sidx)).append(" ").append(sord).toString();
	}

	// 根据conditions转换成sql格式
	public String tranToSQL(String prefix) {
		StringBuilder sb = new StringBuilder("");

		if (null != filterSearch) {
			List&lt;searchrule&gt; rules = filterSearch.getRules();
			int count = 0;
			if (null != rules &#038;&#038; (count = rules.size()) &gt; 0) {
				for (SearchRule rule : rules) {
					if (null != rule.getField() &#038;&#038; null != rule.getData()
							&#038;&#038; null != rule.getOp()) {
						if ("eq".equalsIgnoreCase(rule.getOp())) {

							sb.append(rule.getField()).append(" = ")
									.append("'").append(rule.getData()).append(
											"'");

						} else if ("nq".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" != ").append(
									"'").append(rule.getData()).append("'");
						} else if ("lt".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" &lt; ")
									.append("'").append(rule.getData()).append(
											"'");
						} else if ("le".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" &lt;= ").append(
									"'").append(rule.getData()).append("'");
						} else if ("gt".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" &gt; ")
									.append("'").append(rule.getData()).append(
											"'");
						} else if ("ge".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" &gt;= ").append(
									"'").append(rule.getData()).append("'");
						} else if ("bw".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" like ").append(
									"'").append(rule.getData()).append("%")
									.append("'");
						} else if ("ew".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" like ").append(
									"'").append("%").append(rule.getData())
									.append("'");
						} else if ("cn".equalsIgnoreCase(rule.getOp())) {
							if (null != prefix) {
								sb.append(prefix).append(".");
							}
							sb.append(rule.getField()).append(" like ").append(
									"'").append("%").append(rule.getData())
									.append("%").append("'");
						} else {

						}
						count--;
						if (count &gt; 0) {
							if (null != filterSearch.getGroupOp()) {
								if (filterSearch.getGroupOp().equals("and"))
									sb.append(" and ");
								else
									sb.append(" or ");
							}

						}
					}

				}
			}
		}
		return sb.toString();
	}

	// 装载
	@SuppressWarnings("unchecked")
	private void conditions() {
		// 初始化，如果request为空，说明是从set进来的。
		init();

		// 分拆，全部写入filersearch
		if (null != _search &#038;&#038; "true".equalsIgnoreCase(_search)) {
			// 先写多选择的，一般有多选择就不会有单选择。
			if (null != filters &#038;&#038; filters.length() &gt; 0) {
				Map m = new HashMap();
				m.put("rules", SearchRule.class);
				filterSearch = (FilterSearch) JsonUtils.getDTOList(filters,
						FilterSearch.class, m);

			} else {
				if (null != searchOper &#038;&#038; null != searchString
						&#038;&#038; null != searchField) {
					SearchRule rule = new SearchRule();
					rule.setData(searchString);
					rule.setOp(searchOper);
					rule.setField(doTables(searchField));
					filterSearch = new FilterSearch();
					filterSearch.setGroupOp(null);
					List&lt;/searchrule&gt;&lt;searchrule&gt; rules = new ArrayList&lt;/searchrule&gt;&lt;searchrule&gt;();
					rules.add(rule);
					filterSearch.setRules(rules);
				}
			}
		}

	}

	private  void init() {
		if (request != null) {
			_search = request.getParameter("_search");
			searchOper = request.getParameter("searchOper");
			searchString = request.getParameter("searchString");
			searchField = request.getParameter("searchField");
			filters = request.getParameter("filters");
			sidx = request.getParameter("sidx");
			sord = request.getParameter("sord");
		}
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public String get_search() {
		return _search;
	}

	public void set_search(String _search) {
		this._search = _search;
	}

	public String getSearchField() {
		return searchField;
	}

	public void setSearchField(String searchField) {
		this.searchField = searchField;
	}

	public String getSearchOper() {
		return searchOper;
	}

	public void setSearchOper(String searchOper) {
		this.searchOper = searchOper;
	}

	public String getSearchString() {
		return searchString;
	}

	public void setSearchString(String searchString) {
		this.searchString = searchString;
	}

	public String getFilters() {
		return filters;
	}

	public void setFilters(String filters) {
		this.filters = filters;
	}

	public String getSidx() {
		return sidx;
	}

	public void setSidx(String sidx) {
		this.sidx = sidx;
	}

	public String getSord() {
		return sord;
	}

	public void setSord(String sord) {
		this.sord = sord;
	}

	public FilterSearch getFilterSearch() {
		return filterSearch;
	}

	public void setFilterSearch(FilterSearch filterSearch) {
		this.filterSearch = filterSearch;
	}

	private String doTables(String str){
		if(str.startsWith("__")){
			str = str.substring(2);
			return str.replaceAll("_", ".");
		} else {
			return str;
		}

	}
}
&lt;/searchrule&gt;</pre>
<p>其中，先不要去理睬dotables函数是做什么的。</p>
<p>json工具类参照<a href="http://www.mrzeng.com/post/json-utils.html">json工具类</a>进行。</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid_base_study_8-2.html" title="jqGrid基础学习：8jqGrid中在导航条使用按钮">jqGrid基础学习：8jqGrid中在导航条使用按钮</a><br /><small>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。

使用默认的方法
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下

jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edi...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-base-study-11.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：10jqGrid的多字段查询</title>
		<link>http://www.mrzeng.com/post/jqgrid-base-study-10.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-base-study-10.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 07:24:10 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=211</guid>
		<description><![CDATA[多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。 启用多条件查询的方法，是加上.searchGrid({multipleSearch:true}); 即可。 $("#grid").jqGrid({ …… }).navGrid('#nav',{edit:false,add:false,del:false}) .searchGrid({multipleSearch:true}); 关于搜索和后台的交互放在下一章。 相关日志jqGrid进阶教程：3、jqGrid的数据格式化二jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。 我们接上面的例子 $("#grid_id").jqGrid({ ... colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ], ... }); ...jqGrid例子文件下载最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。 jqGrid 由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框， 例如 [caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption] 这种问题的原因多半是因为html的标准问题，即其写法为 如果要让样式正常，要采用写法如下 ...jqGrid基础学习：11jqGrid的查询时和后台的交互jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。 单字段 我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下 [caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption] 由此，我们看出单字段查询...jqGrid基础学习：8jqGrid中在导航条使用按钮jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。 使用默认的方法 系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下 jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{ //这里可以指定edi...]]></description>
			<content:encoded><![CDATA[<p>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。<br />
<span id="more-211"></span><br />
<div id="attachment_379" class="wp-caption alignnone" style="width: 728px"><a href="http://huashui.org/wp-content/uploads/2010/03/20100128134414924577274551e4198d3c98d15642641f.jpg"><img src="http://huashui.org/wp-content/uploads/2010/03/20100128134414924577274551e4198d3c98d15642641f.jpg" alt="jqGrid多字段查询" title="20100128134414924577274551e4198d3c98d15642641f" width="718" height="256" class="size-full wp-image-379" /></a><p class="wp-caption-text">jqGrid多字段查询</p></div></p>
<p>启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。</p>
<pre class=prettyprint>
    $("#grid").jqGrid({
     ……
    }).navGrid('#nav',{edit:false,add:false,del:false})
    .searchGrid({multipleSearch:true});
</pre>
<p>关于搜索和后台的交互放在下一章。</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid_base_study_8-2.html" title="jqGrid基础学习：8jqGrid中在导航条使用按钮">jqGrid基础学习：8jqGrid中在导航条使用按钮</a><br /><small>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。

使用默认的方法
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下

jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edi...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-base-study-10.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：8jqGrid中在导航条使用按钮</title>
		<link>http://www.mrzeng.com/post/jqgrid_base_study_8-2.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid_base_study_8-2.html#comments</comments>
		<pubDate>Tue, 02 Mar 2010 08:22:44 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=204</guid>
		<description><![CDATA[jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。 使用默认的方法 系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下 jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{ //这里可以指定edit的一些属性和方法，如果不需要配置，可以不要这对大括号 },{ //这里可以指定add的一些属性和方法，如果不需要配置，可以不要这对大括号 },{ //这里可以指定del的一些属性和方法，如果不需要配置，可以不要这对大括号 },{ //这里可以指定搜索的一些属性，如果不需要配置，可以不要这对大括号 }); 自定义按钮 jQuery("#list").jqGrid('navButtonAdd','#pager',{ caption: "", // buttonicon:"ui-icon-print", title: "选择要的列", onClickButton : function (){ jQuery("#list").jqGrid('columnChooser'); } }).navSeparatorAdd("#pager",{sepclass : "ui-separator",sepcontent: ''}).navButtonAdd('#pager',{ caption:"", title:"导出数据", buttonicon:"ui-icon-disk", onClickButton: function(){ jAlert("您没有选择一行，将导出所有数据"); }, position:"last" }); navSeparatorAdd是增加一个&#124;进行按钮分割. 也可以参考下官方的一些属性配置 $.jgrid = { ... search : { caption: "Search...", Find: "Find", Reset: "Reset", odata [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。<br />
<span id="more-204"></span><br />
<strong>使用默认的方法</strong><br />
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下</p>
<pre lang="html4strict">
jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edit的一些属性和方法，如果不需要配置，可以不要这对大括号
},{
//这里可以指定add的一些属性和方法，如果不需要配置，可以不要这对大括号
},{
//这里可以指定del的一些属性和方法，如果不需要配置，可以不要这对大括号

},{
//这里可以指定搜索的一些属性，如果不需要配置，可以不要这对大括号
});
</pre>
<p><strong>自定义按钮</strong></p>
<pre class=prettyprint>
 jQuery("#list").jqGrid('navButtonAdd','#pager',{
    caption: "",
   // buttonicon:"ui-icon-print",
    title: "选择要的列",
    onClickButton : function (){
        jQuery("#list").jqGrid('columnChooser');
    }

}).navSeparatorAdd("#pager",{sepclass : "ui-separator",sepcontent: ''}).navButtonAdd('#pager',{
					   caption:"",
					   title:"导出数据",
					   buttonicon:"ui-icon-disk",
					   onClickButton: function(){
					     jAlert("您没有选择一行，将导出所有数据");
					   },
					   position:"last"
					});
</pre>
<p>navSeparatorAdd是增加一个|进行按钮分割.</p>
<p>也可以参考下<a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:pager">官方</a>的一些属性配置</p>
<pre class=prettyprint>
$.jgrid = {
...
   search : {
     caption: "Search...",
     Find: "Find",
     Reset: "Reset",
     odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain'],
     groupOps: [ { op: "AND", text: "all" }, { op: "OR", text: "any" } ],
     matchText: " match",
     rulesText: " rules"
   },
   edit : {
     addCaption: "Add Record",
     editCaption: "Edit Record",
     bSubmit: "Submit",
     bCancel: "Cancel",
     bClose: "Close",
     saveData: "Data has been changed! Save changes?",
     bYes : "Yes",
     bNo : "No",
     bExit : "Cancel",
  },
  view : {
    caption: "View Record",
    bClose: "Close"
  },
  del : {
    caption: "Delete",
    msg: "Delete selected record(s)?",
    bSubmit: "Delete",
    bCancel: "Cancel"
  },
  nav : {
    edittext: "",
    edittitle: "Edit selected row",
    addtext:"",
    addtitle: "Add new row",
    deltext: "",
    deltitle: "Delete selected row",
    searchtext: "",
    searchtitle: "Find records",
    refreshtext: "",
    refreshtitle: "Reload Grid",
    alertcap: "Warning",
    alerttext: "Please, select row",
    viewtext: "",
    viewtitle: "View selected row"
  },
...
</pre>
<table class="bbcode">
<tr>
<td>属性</td>
<td>类型</td>
<td>说明</td>
<td>默认值</td>
</tr>
<tr>
<td>add</td>
<td>boolean</td>
<td>是否启用新增功能，当点击按钮时会触发editGridRow事件</td>
<td>true</td>
</tr>
<tr>
<td>addicon</td>
<td>string</td>
<td>给新增功能设置图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-plus</td>
</tr>
<tr>
<td>addtext</td>
<td>string</td>
<td>新增按钮上的文字</td>
<td>空</td>
</tr>
<tr>
<td>addtitle</td>
<td>string</td>
<td>当鼠标移到新增按钮上时显示的提示</td>
<td>新增一行</td>
</tr>
<tr>
<td>alertcap</td>
<td>string</td>
<td>当我们edit,delete or view一行记录时出现的提示信息</td>
<td>警告</td>
</tr>
<tr>
<td>alerttext</td>
<td>string</td>
<td>当edit,delete or view一行记录时的文本提示</td>
<td>请选择一行记录</td>
</tr>
<tr>
<td>closeOnEscape</td>
<td>boolean</td>
<td>是否可以使用esc键关闭对话框</td>
<td>true</td>
</tr>
<tr>
<td>del</td>
<td>boolean</td>
<td>是否启用删除功能，启用时会触发事件delGridRow </td>
<td>true</td>
</tr>
<tr>
<td>delicon</td>
<td>string</td>
<td>设置删除按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-trash</td>
</tr>
<tr>
<td>deltext</td>
<td>string</td>
<td>设置到删除按钮上的文字信息</td>
<td>空</td>
</tr>
<tr>
<td>deltitle</td>
<td>string</td>
<td>当鼠标移到删除按钮上时出现的提示</td>
<td>删除锁选择的行</td>
</tr>
<tr>
<td>edit</td>
<td>boolean</td>
<td>是否启用可编辑功能，当编辑时会触发事件editGridRow </td>
<td>true</td>
</tr>
<tr>
<td>editicon</td>
<td>string</td>
<td>设置编辑按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-pencil</td>
</tr>
<tr>
<td>edittext</td>
<td>string</td>
<td>编辑按钮上文字</td>
<td>空</td>
</tr>
<tr>
<td>edittitle</td>
<td>string</td>
<td>当鼠标移到编辑按钮上出现的提示信息</td>
<td>编辑所选择的行</td>
</tr>
<tr>
<td>position</td>
<td>string</td>
<td>定义按钮位置，可选值left, center and right. </td>
<td>left</td>
</tr>
<tr>
<td>refresh</td>
<td>boolean</td>
<td>是否启用刷新按钮，当点击刷新按钮时会触发trigger(“reloadGrid”)事件，而且会清空搜索条件值</td>
<td>true</td>
</tr>
<tr>
<td>refreshicon</td>
<td>string</td>
<td>设置刷新图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-refresh</td>
</tr>
<tr>
<td>refreshtext</td>
<td>string</td>
<td>刷新按钮上文字信息</td>
<td>空</td>
</tr>
<tr>
<td>refreshtitle</td>
<td>string</td>
<td>当鼠标移到刷新按钮上的提示信息</td>
<td>重新加载</td>
</tr>
<tr>
<td>refreshstate</td>
<td>string</td>
<td>指明表格如何刷新。firstpage：从第一页开始刷新；current：只刷新当前页内容</td>
<td>firstpage</td>
</tr>
<tr>
<td>afterRefresh</td>
<td>function</td>
<td>当点击刷新按钮之后触发此事件</td>
<td>null</td>
</tr>
<tr>
<td>search</td>
<td>boolean</td>
<td>是否启用搜索按钮，会触发searchGrid 事件</td>
<td>true</td>
</tr>
<tr>
<td>searchhicon</td>
<td>string</td>
<td>设置搜索按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-search</td>
</tr>
<tr>
<td>searchtext</td>
<td>string</td>
<td>搜索按钮上的文字</td>
<td>空</td>
</tr>
<tr>
<td>searchtitle</td>
<td>string</td>
<td>当鼠标移到搜索按钮上的提示信息</td>
<td>搜索</td>
</tr>
<tr>
<td>view</td>
<td>boolean</td>
<td>是否启用查看按钮，会触发事件viewGridRow </td>
<td>false</td>
</tr>
<tr>
<td>viewicon</td>
<td>string</td>
<td>设置查看按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-document</td>
</tr>
<tr>
<td>viewtext</td>
<td>string</td>
<td>查看按钮上文字</td>
<td>空</td>
</tr>
<tr>
<td>viewtitle</td>
<td>string</td>
<td>当鼠标移到查看按钮上的提示信息</td>
<td>查看所选记录</td>
</tr>
</table>
<p>自定义按钮的官方的说明：</p>
<pre class=prettyprint>
&lt;script&gt;
...
jQuery("#grid_id").navGrid("#pager",...).navButtonAdd("#pager",{parameters});
...
&lt;/script&gt; 
</pre>
<p>或者用新API</p>
<pre class=prettyprint>
&lt;script&gt;
...
jQuery("#grid_id").jqGrid('navGrid',"#pager",...).jqGrid('navButtonAdd',"#pager",{parameters});
...
&lt;/script&gt;
</pre>
<p>默认参数</p>
<pre class=prettyprint>
{ caption:"NewButton", buttonicon:"ui-icon-newwin", onClickButton:null, position: "last", title:"", cursor: "pointer"}
</pre>
<p>caption：按钮名称，可以为空，string类型<br />
buttonicon：按钮的图标，string类型，必须为UI theme图标<br />
onClickButton：按钮事件，function类型，默认null<br />
position：first或者last，按钮位置<br />
title：string类型，按钮的提示信息<br />
cursor：string类型，光标类型，默认为pointer<br />
id：string类型，按钮id </p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid_base_study_8-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：8jqGrid中在导航条使用按钮</title>
		<link>http://www.mrzeng.com/post/jqgrid_base_study_8.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid_base_study_8.html#comments</comments>
		<pubDate>Tue, 02 Mar 2010 08:22:12 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=191</guid>
		<description><![CDATA[jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。 使用默认的方法 系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下 jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{ //这里可以指定edit的一些属性和方法，如果不需要配置，可以不要这对大括号 },{ //这里可以指定add的一些属性和方法，如果不需要配置，可以不要这对大括号 },{ //这里可以指定del的一些属性和方法，如果不需要配置，可以不要这对大括号 },{ //这里可以指定搜索的一些属性，如果不需要配置，可以不要这对大括号 }); 自定义按钮 jQuery("#list").jqGrid('navButtonAdd','#pager',{ caption: "", // buttonicon:"ui-icon-print", title: "选择要的列", onClickButton : function (){ jQuery("#list").jqGrid('columnChooser'); } }).navSeparatorAdd("#pager",{sepclass : "ui-separator",sepcontent: ''}).navButtonAdd('#pager',{ caption:"", title:"导出数据", buttonicon:"ui-icon-disk", onClickButton: function(){ jAlert("您没有选择一行，将导出所有数据"); }, position:"last" }); navSeparatorAdd是增加一个&#124;进行按钮分割. 也可以参考下官方的一些属性配置 $.jgrid = { ... search : { caption: "Search...", Find: "Find", Reset: "Reset", odata [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid中可以再导航条上设置按钮，其中jqGrid已经默认设置了一些按钮，此外，用户也可以自定义自己的按钮。<br />
<span id="more-191"></span><br />
<strong>使用默认的方法</strong><br />
系统中默认的按钮主要是对数据进行CRUD的操作的按钮。方法如下</p>
<pre class=prettyprint>
jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,view:true},{
//这里可以指定edit的一些属性和方法，如果不需要配置，可以不要这对大括号
},{
//这里可以指定add的一些属性和方法，如果不需要配置，可以不要这对大括号
},{
//这里可以指定del的一些属性和方法，如果不需要配置，可以不要这对大括号

},{
//这里可以指定搜索的一些属性，如果不需要配置，可以不要这对大括号
});
</pre>
<p><strong>自定义按钮</strong></p>
<pre class=prettyprint>
 jQuery("#list").jqGrid('navButtonAdd','#pager',{
    caption: "",
   // buttonicon:"ui-icon-print",
    title: "选择要的列",
    onClickButton : function (){
        jQuery("#list").jqGrid('columnChooser');
    }

}).navSeparatorAdd("#pager",{sepclass : "ui-separator",sepcontent: ''}).navButtonAdd('#pager',{
					   caption:"",
					   title:"导出数据",
					   buttonicon:"ui-icon-disk",
					   onClickButton: function(){
					     jAlert("您没有选择一行，将导出所有数据");
					   },
					   position:"last"
					});
</pre>
<p>navSeparatorAdd是增加一个|进行按钮分割.</p>
<p>也可以参考下<a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:pager">官方</a>的一些属性配置</p>
<pre class=prettyprint>
$.jgrid = {
...
   search : {
     caption: "Search...",
     Find: "Find",
     Reset: "Reset",
     odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain'],
     groupOps: [ { op: "AND", text: "all" }, { op: "OR", text: "any" } ],
     matchText: " match",
     rulesText: " rules"
   },
   edit : {
     addCaption: "Add Record",
     editCaption: "Edit Record",
     bSubmit: "Submit",
     bCancel: "Cancel",
     bClose: "Close",
     saveData: "Data has been changed! Save changes?",
     bYes : "Yes",
     bNo : "No",
     bExit : "Cancel",
  },
  view : {
    caption: "View Record",
    bClose: "Close"
  },
  del : {
    caption: "Delete",
    msg: "Delete selected record(s)?",
    bSubmit: "Delete",
    bCancel: "Cancel"
  },
  nav : {
    edittext: "",
    edittitle: "Edit selected row",
    addtext:"",
    addtitle: "Add new row",
    deltext: "",
    deltitle: "Delete selected row",
    searchtext: "",
    searchtitle: "Find records",
    refreshtext: "",
    refreshtitle: "Reload Grid",
    alertcap: "Warning",
    alerttext: "Please, select row",
    viewtext: "",
    viewtitle: "View selected row"
  },
...
</pre>
<table class="bbcode">
<tr>
<td>属性</td>
<td>类型</td>
<td>说明</td>
<td>默认值</td>
</tr>
<tr>
<td>add</td>
<td>boolean</td>
<td>是否启用新增功能，当点击按钮时会触发editGridRow事件</td>
<td>true</td>
</tr>
<tr>
<td>addicon</td>
<td>string</td>
<td>给新增功能设置图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-plus</td>
</tr>
<tr>
<td>addtext</td>
<td>string</td>
<td>新增按钮上的文字</td>
<td>空</td>
</tr>
<tr>
<td>addtitle</td>
<td>string</td>
<td>当鼠标移到新增按钮上时显示的提示</td>
<td>新增一行</td>
</tr>
<tr>
<td>alertcap</td>
<td>string</td>
<td>当我们edit,delete or view一行记录时出现的提示信息</td>
<td>警告</td>
</tr>
<tr>
<td>alerttext</td>
<td>string</td>
<td>当edit,delete or view一行记录时的文本提示</td>
<td>请选择一行记录</td>
</tr>
<tr>
<td>closeOnEscape</td>
<td>boolean</td>
<td>是否可以使用esc键关闭对话框</td>
<td>true</td>
</tr>
<tr>
<td>del</td>
<td>boolean</td>
<td>是否启用删除功能，启用时会触发事件delGridRow </td>
<td>true</td>
</tr>
<tr>
<td>delicon</td>
<td>string</td>
<td>设置删除按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-trash</td>
</tr>
<tr>
<td>deltext</td>
<td>string</td>
<td>设置到删除按钮上的文字信息</td>
<td>空</td>
</tr>
<tr>
<td>deltitle</td>
<td>string</td>
<td>当鼠标移到删除按钮上时出现的提示</td>
<td>删除锁选择的行</td>
</tr>
<tr>
<td>edit</td>
<td>boolean</td>
<td>是否启用可编辑功能，当编辑时会触发事件editGridRow </td>
<td>true</td>
</tr>
<tr>
<td>editicon</td>
<td>string</td>
<td>设置编辑按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-pencil</td>
</tr>
<tr>
<td>edittext</td>
<td>string</td>
<td>编辑按钮上文字</td>
<td>空</td>
</tr>
<tr>
<td>edittitle</td>
<td>string</td>
<td>当鼠标移到编辑按钮上出现的提示信息</td>
<td>编辑所选择的行</td>
</tr>
<tr>
<td>position</td>
<td>string</td>
<td>定义按钮位置，可选值left, center and right. </td>
<td>left</td>
</tr>
<tr>
<td>refresh</td>
<td>boolean</td>
<td>是否启用刷新按钮，当点击刷新按钮时会触发trigger(“reloadGrid”)事件，而且会清空搜索条件值</td>
<td>true</td>
</tr>
<tr>
<td>refreshicon</td>
<td>string</td>
<td>设置刷新图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-refresh</td>
</tr>
<tr>
<td>refreshtext</td>
<td>string</td>
<td>刷新按钮上文字信息</td>
<td>空</td>
</tr>
<tr>
<td>refreshtitle</td>
<td>string</td>
<td>当鼠标移到刷新按钮上的提示信息</td>
<td>重新加载</td>
</tr>
<tr>
<td>refreshstate</td>
<td>string</td>
<td>指明表格如何刷新。firstpage：从第一页开始刷新；current：只刷新当前页内容</td>
<td>firstpage</td>
</tr>
<tr>
<td>afterRefresh</td>
<td>function</td>
<td>当点击刷新按钮之后触发此事件</td>
<td>null</td>
</tr>
<tr>
<td>search</td>
<td>boolean</td>
<td>是否启用搜索按钮，会触发searchGrid 事件</td>
<td>true</td>
</tr>
<tr>
<td>searchhicon</td>
<td>string</td>
<td>设置搜索按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-search</td>
</tr>
<tr>
<td>searchtext</td>
<td>string</td>
<td>搜索按钮上的文字</td>
<td>空</td>
</tr>
<tr>
<td>searchtitle</td>
<td>string</td>
<td>当鼠标移到搜索按钮上的提示信息</td>
<td>搜索</td>
</tr>
<tr>
<td>view</td>
<td>boolean</td>
<td>是否启用查看按钮，会触发事件viewGridRow </td>
<td>false</td>
</tr>
<tr>
<td>viewicon</td>
<td>string</td>
<td>设置查看按钮的图标，只有UI theme里的图标才可以使用</td>
<td>ui-icon-document</td>
</tr>
<tr>
<td>viewtext</td>
<td>string</td>
<td>查看按钮上文字</td>
<td>空</td>
</tr>
<tr>
<td>viewtitle</td>
<td>string</td>
<td>当鼠标移到查看按钮上的提示信息</td>
<td>查看所选记录</td>
</tr>
</table>
<p>自定义按钮的官方的说明：</p>
<pre class=prettyprint>
&lt;script&gt;
...
jQuery("#grid_id").navGrid("#pager",...).navButtonAdd("#pager",{parameters});
...
&lt;/script&gt; 
</pre>
<p>或者用新API</p>
<pre class=prettyprint>
&lt;script&gt;
...
jQuery("#grid_id").jqGrid('navGrid',"#pager",...).jqGrid('navButtonAdd',"#pager",{parameters});
...
&lt;/script&gt;
</pre>
<p>默认参数</p>
<pre class=prettyprint>
{ caption:"NewButton", buttonicon:"ui-icon-newwin", onClickButton:null, position: "last", title:"", cursor: "pointer"}
</pre>
<p>caption：按钮名称，可以为空，string类型<br />
buttonicon：按钮的图标，string类型，必须为UI theme图标<br />
onClickButton：按钮事件，function类型，默认null<br />
position：first或者last，按钮位置<br />
title：string类型，按钮的提示信息<br />
cursor：string类型，光标类型，默认为pointer<br />
id：string类型，按钮id </p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid_base_study_8.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：7jqGrid中使用分页</title>
		<link>http://www.mrzeng.com/post/jqgrid-base-study-7.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-base-study-7.html#comments</comments>
		<pubDate>Tue, 02 Mar 2010 07:14:15 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=200</guid>
		<description><![CDATA[jqGrid分页首先要在页面设置一个DIV的层。例如,在第一章就提到的 同时，要在jqGrid的配置中加入 jQuery("#grid_id").jqGrid({ ... pager : '#pager', ... }); 参照第二章 效果如下 同时，这jqGrid中，在分页可以设定各种属性，例如没有找到数据时显示的提示。 jQuery("#grid_id").jqGrid({ ... pager : '#pager', emptyrecords: "Nothing to display", ... }); 而这些，也可以再i18n的文件中进行配置。很少这样直接更改。系统默认的显示是 recordtext: "View {0} - {1} of {2}", emptyrecords: "No records to view", loadtext: "Loading...", pgtext : "Page {0} of {1}" 在分页导航条中，还可以对属性进行修改，分页导航的属性有 属性名 类型 说明 默认值 是否可以被修改 lastpage integer 只读属性，总页数 0 NO [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid分页首先要在页面设置一个DIV的层。例如,在<a href="http://huashui.org/post/jqgrid_base_study_1.html">第一章</a>就提到的</p>
<pre lang="html4strict">
<table id="list"></table>
<div id="pager"></div>

<!--分页专用,如果要使用分页导航必须有该标记-->
</pre>
<p><span id="more-200"></span><br />
同时，要在jqGrid的配置中加入</p>
<pre lang="javascript">
jQuery("#grid_id").jqGrid({
...
   pager : '#pager',
...
});
</pre>
<p>参照<a href="http://huashui.org/post/jqgrid-base-study-2.html">第二章</a><br />
效果如下<br />
<div id="attachment_327" class="wp-caption alignnone" style="width: 310px"><a href="http://huashui.org/wp-content/uploads/2010/03/pager.png"><img src="http://huashui.org/wp-content/uploads/2010/03/pager-300x18.png" alt="分页实例" title="pager" width="300" height="18" class="size-medium wp-image-327" /></a><p class="wp-caption-text">分页实例</p></div></p>
<p>同时，这jqGrid中，在分页可以设定各种属性，例如没有找到数据时显示的提示。</p>
<pre class=prettyprint>
jQuery("#grid_id").jqGrid({
...
   pager : '#pager',
   emptyrecords: "Nothing to display",
...
});
</pre>
<p>而这些，也可以再i18n的文件中进行配置。很少这样直接更改。系统默认的显示是</p>
<pre class=prettyprint>
recordtext: "View {0} - {1} of {2}",
	        emptyrecords: "No records to view",
		loadtext: "Loading...",
		pgtext : "Page {0} of {1}"
</pre>
<p>在分页导航条中，还可以对属性进行修改，分页导航的属性有</p>
<table>
<tr>
<td>属性名</td>
<td>类型</td>
<td>说明</td>
<td>默认值</td>
<td>是否可以被修改</td>
</tr>
<tr>
<td>lastpage</td>
<td>integer</td>
<td>只读属性，总页数</td>
<td>0</td>
<td>NO</td>
</tr>
<tr>
<td>pager</td>
<td>mixed</td>
<td>导航栏对象，必须是一个有效的html元素，位置可以随意</td>
<td>空字符串</td>
<td>NO</td>
</tr>
<tr>
<td>pagerpos</td>
<td>string</td>
<td>定义导航栏的位置，默认分为三部分：翻页，导航工具及记录信息</td>
<td>center</td>
<td>NO</td>
</tr>
<tr>
<td>pgbuttons</td>
<td>boolean</td>
<td>是否显示翻页按钮</td>
<td>true</td>
<td>NO</td>
</tr>
<tr>
<td>pginput</td>
<td>boolean</td>
<td>是否显示跳转页面的输入框</td>
<td>true</td>
<td>NO</td>
</tr>
<tr>
<td>pgtext</td>
<td>string</td>
<td>页面信息，第一个值是当前页第二个值是总页数</td>
<td>语言包</td>
<td>YES</td>
</tr>
<tr>
<td>reccount</td>
<td>integer</td>
<td>只读属性，实际记录数，千万不能跟records 参数搞混了，通常情况下他们是相同的，假如我们定义rowNum=15，但我们从服务器端返回的记录为20即records=20，而reccount=15，表格中也显示15条记录。</td>
<td>0</td>
<td>NO</td>
</tr>
<tr>
<td>recordpos</td>
<td>string</td>
<td>定义记录信息的位置，可选值：left, center, right</td>
<td>right</td>
<td>NO</td>
</tr>
<tr>
<td>records</td>
<td>integer</td>
<td>只读属性，从服务器端返回的记录数</td>
<td>none</td>
<td>NO</td>
</tr>
<tr>
<td>recordtext</td>
<td>string</td>
<td>显示记录的信息，只有当viewrecords为true时起效，且记录数必须大于0</td>
<td>语言包</td>
<td>yes</td>
</tr>
<tr>
<td>rowList</td>
<td>array[]</td>
<td>可以改变表格可以显示的记录数，格式为[10,20,30]</td>
<td>空array[]</td>
<td>no</td>
</tr>
<tr>
<td>rowNum</td>
<td>integer</td>
<td>设置表格可以显示的记录数</td>
<td>20</td>
<td>yes</td>
</tr>
<tr>
<td>viewrecords</td>
<td>boolean</td>
<td>是否要显示总记录数信息</td>
<td>false</td>
<td>no</td>
</tr>
</table>
<p>所有这些参数都是可以修改的，比如： </p>
<pre class=prettyprint>
&lt;script&gt;
...
jQuery("#grid_id").setGridParam({rowNum:10}).trigger("reloadGrid");
...
&lt;/script&gt;
</pre>
<p>同时，分页有一个事件，很少需要用到</p>
<table class="bbcode">
<tr>
<td>事件名</td>
<td>参数</td>
<td>说明</td>
</tr>
<tr>
<td>onPaging</td>
<td>pgButton</td>
<td>当点击翻页按钮但还为展现数据时触发此事件，当然这跳转栏输入页码改变页时也同样触发此事件。参数pgButton可选值：<br />
		first,last,prev,next </td>
</tr>
</table>
<p>同时要注意和后台的交互。jqGrid在分页的时候向后台传递的参数有</p>
<pre class=prettyprint>
	/*
	 * 分页
	 */
	private Integer page;// 当前页
	private Integer total;// 总页数
	private Integer pageSize = 20;// 每页显示多少
	private Integer records;// 总记录数
	private List&lt;studentbean&gt; rows;// 记录
&lt;/studentbean&gt;</pre>
<p>所以，我们可以通过书写一份分页公共类来进行。<br />
分页Bean</p>
<pre class=prettyprint>
public class Page {

	private int count = 0; // 记录总数

	private int pageSize = 20; // 每页显示记录数

	private int pageCount = 0; // 总页数

	private int page = 1; // 当前页数

	private String totalCountSQL;// 得到总记录数sql语句

	private String listSQL;// 得到查询记录sql语句

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getTotalCountSQL() {
		return totalCountSQL;
	}

	public void setTotalCountSQL(String totalCountSQL) {
		this.totalCountSQL = totalCountSQL;
	}

	public String getListSQL() {
		return listSQL;
	}

	public void setListSQL(String listSQL) {
		this.listSQL = listSQL;
	}

}
</pre>
<p>分页的接口</p>
<pre class=prettyprint>
public interface IPage {

	public List getList(PageBean page);
	public List getList(PageBean page, Map param);

	public Long getTotalCount(PageBean p,Map param);

	public Long getTotalCount(PageBean page);

}
</pre>
<p>分页实现</p>
<pre class=prettyprint>
@Service("page")
@SuppressWarnings("unchecked")
public class PageImpl implements IPage {
	@Resource
	private SessionFactory sessionFactory;

	public List getList(PageBean page) {
		Query query = sessionFactory.getCurrentSession().createQuery(
				page.getListSQL());
		query.setMaxResults(page.getPageSize());
		query.setFirstResult((page.getPage() - 1) * page.getPageSize());
		return query.list();
	}

	public List getList(PageBean page, Map param) {

		Query query = sessionFactory.getCurrentSession().createQuery(
				page.getListSQL());
		if (null != param) {
			Iterator it = param.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry entry = (Map.Entry) it.next();
				String key = (String) entry.getKey();
				Object val = entry.getValue();
				query.setParameter(key, val);

			}
		}
		return query.list();
	}

	public Long getTotalCount(PageBean p, Map param) {
		Query query = sessionFactory.getCurrentSession().createQuery(p.getTotalCountSQL());
		if (null != param) {
			Iterator it = param.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry entry = (Map.Entry) it.next();
				String key = (String) entry.getKey();
				Object val = entry.getValue();
				query.setParameter(key, val);

			}
		}
		return (Long) query.uniqueResult();
	}

	public Long getTotalCount(PageBean p) {

		return (Long) sessionFactory.getCurrentSession().createQuery(p.getTotalCountSQL()).uniqueResult();
	}

}
</pre>
<p>Action类完整代码</p>
<pre class=prettyprint>
@ParentPackage("json-default")
@Namespace("/admin/json")
public class StudentListAction implements ServletRequestAware {

	@Resource
	private IPaginate paginate;
	private HttpServletRequest request;

	/*
	 * 分页
	 */
	private Integer page;// 当前页
	private Integer total;// 总页数
	private Integer pageSize = 20;// 每页显示多少
	private Integer records;// 总记录数
	private List&lt;studentbean&gt; rows;// 记录

	public StudentListAction() {
		System.out.println(new Date());

	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	@JSON(serialize = false)
	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getRecords() {
		return records;
	}

	public void setRecords(Integer records) {
		this.records = records;
	}

	public List&lt;/studentbean&gt;&lt;studentbean&gt; getRows() {
		return rows;
	}

	public void setRows(List&lt;/studentbean&gt;&lt;studentbean&gt; rows) {
		this.rows = rows;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;

	}

	@Action(value = "jsondata", results = { @Result(type = "json") })
	public String execute() throws Exception {
		get();

		return com.opensymphony.xwork2.Action.SUCCESS;
	}

	@SuppressWarnings("unchecked")
	private void get() throws Exception {
		PageBean pageBean = new PageBean();
		pageBean.setPage(page);
		pageBean.setPageSize(pageSize);
		JqGridHandler handler = new JqGridHandler(request);
		pageBean.setTotalCountSQL("select count(*) from Student "
				+ handler.getWheres(null, false)
				+ handler.getOrders(null, false));
		pageBean.setListSQL("from Student "
				+ handler.getWheres(null, false)
				+ handler.getOrders(null, false));
		pageBean.setCount(paginate.getTotalCount(pageBean).intValue());

		List&lt;student&gt; list = paginate.getList(pageBean);
		rows = new ArrayList&lt;studentbean&gt;();
		for (Student student : list) {
			StudentBean bean = new StudentBean();
			bean.setAge(student.getAge());
			bean.set__department_id(student.getDepartment().getId());
			bean.setId(student.getId());
			bean.setName(student.getName());
			bean.setSex(student.getSex());
			bean.setDate(student.getDate());
			rows.add(bean);
		}
		total = pageBean.getPageCount();
		records = pageBean.getCount();
	}

}

&lt;/studentbean&gt;&lt;/student&gt;&lt;/studentbean&gt;</pre>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-base-study-7.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：6jqGrid中方法使用</title>
		<link>http://www.mrzeng.com/post/jqgrid-base-study-6.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-base-study-6.html#comments</comments>
		<pubDate>Mon, 08 Feb 2010 02:08:16 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=183</guid>
		<description><![CDATA[jqGrid的方法一般用法如下： ... jQuery("#grid_id").jqGridMethod( parameter1,...parameterN ); ... grid_id 是已经实现定义好的jqGrid。 jqGridMethod 是要应用到jqGrid的方法。 parameter1,…parameterN - 一系列方法。 同时要注意的是，jqGrid方法返回的是jqGrid对象。 方法名 参数 返回值 说明 addJSONData data none 使用传来的data数据填充表格。使用方法：var mygrid = jQuery(”#”+grid_id)[0];var myjsongrid = eval(”(”+jsonresponse.responseText+”)”); mygrid.addJSONData(myjsongrid); myjsongrid = null; jsonresponse =null; addRowData rowid,data, position, srcrowid 成功为true, 否则为false 根据参数插入一行新的数据，rowid为新行的id，data为新行的数据，position为新增行的位置，srcrowid为新增行的参考位置。data数据格式：{name1:value1,name2: value2…} name为在colModel中指定的名称 addXMLData data none 根据传来的数据填充表格。用法：var mygrid = jQuery(”#”+grid_id)[0]; mygrid.addXmlData(xmlresponse.responseXML); clearGridData clearfooter jqGrid对象 清除表格当前加载的数据。如果clearfooter为true时则此方法删除表格最后一行的数据 [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid的方法一般用法如下：</p>
<pre lang="javascript">
<script>
...
jQuery("#grid_id").jqGridMethod( parameter1,...parameterN );
...
</script>
</pre>
<p><em>grid_id </em>是已经实现定义好的jqGrid。<br />
<em>jqGridMethod </em>是要应用到jqGrid的方法。<br />
<em>parameter1,…parameterN </em>- 一系列方法。<br />
<span id="more-183"></span><br />
同时要注意的是，<strong>jqGrid方法返回的是jqGrid对象</strong>。</p>
<table border="1">
<tbody>
<tr>
<td>方法名</td>
<td>参数</td>
<td>返回值</td>
<td>说明</td>
</tr>
<tr>
<td>addJSONData</td>
<td>data</td>
<td>none</td>
<td>使用传来的data数据填充表格。使用方法：var mygrid = jQuery(”#”+grid_id)[0];var myjsongrid = eval(”(”+jsonresponse.responseText+”)”); mygrid.addJSONData(myjsongrid); myjsongrid = null; jsonresponse =null;</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>addRowData</td>
<td>rowid,data, position, srcrowid</td>
<td>成功为true, 否则为false</td>
<td>根据参数插入一行新的数据，rowid为新行的id，data为新行的数据，position为新增行的位置，srcrowid为新增行的参考位置。data数据格式：{name1:value1,name2: value2…} name为在colModel中指定的名称</td>
</tr>
<tr>
<td>addXMLData</td>
<td>data</td>
<td>none</td>
<td>根据传来的数据填充表格。用法：var mygrid = jQuery(”#”+grid_id)[0]; mygrid.addXmlData(xmlresponse.responseXML);</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>clearGridData</td>
<td>clearfooter</td>
<td>jqGrid对象</td>
<td>清除表格当前加载的数据。如果clearfooter为true时则此方法删除表格最后一行的数据</td>
</tr>
<tr>
<td>delRowData</td>
<td>rowid</td>
<td>成功为true否则为false</td>
<td>根据rowid删除行，但不会从服务器端删除数据</td>
</tr>
<tr>
<td>footerData</td>
<td>action,data, format</td>
<td>jgGrid对象</td>
<td>设置或者取得底部数据。action：“get”或者“set”，默认为“get”，如果为“get”返回值为name:value，name为colModel中名称。如果为“set”则值为name：value，name是colModel中的名称。format：默认为true，当为true时，在设置新值时会调用formatter格式化数值</td>
</tr>
<tr>
<td>getCell</td>
<td>rowid, iCol</td>
<td>单元格内容</td>
<td>返回指定rowid，iCol的单元格内容，iCol既可以是当前列在colModel中的位置索引也可以是name值。注意：在编辑行或者单元格时不能使用此方法，此时返回的并不是改变的值，而是原始值</td>
</tr>
<tr>
<td>getCol</td>
<td>colname, returntype, mathoperation</td>
<td>array[] or value</td>
<td>返回列的值。colname既可以是当前列在colModel中的位置索引也可以是name值。returntype指定返回数据的类型，默认为false。当为false时，返回的数组中只包含列的值，当为true时返回数组是对象数组，具体格式 {id:rowid, value:cellvalue} ，id为行的id，value为列的值。如： [{id:1,value:1},{id:2,value:2}…]。mathoperation 可选值为&#8217;sum, &#8216;avg&#8217;, &#8216;count&#8217;</td>
</tr>
<tr>
<td>getDataIDs</td>
<td>none</td>
<td>array[]</td>
<td>返回当前grid里所有数据的id</td>
</tr>
<tr>
<td>getGridParam</td>
<td>name</td>
<td>mixed value</td>
<td>返回请求的参数信息</td>
</tr>
<tr>
<td>getInd</td>
<td>rowid,rowcontent</td>
<td>mixed</td>
<td>如果rowcontent为false，返回行所在的索引位置，id为行id。rowcontent默认为false。如果rowconent为ture则返回的为行对象，如果找不到行则返回false</td>
</tr>
<tr>
<td>getRowData</td>
<td>rowid or none</td>
<td>array{}</td>
<td>返回指定行的数据，返回数据类型为name:value，name为colModel中的名称，value为所在行的列的值，如果根据rowid找不到则返回空。在编辑模式下不能用此方法来获取数据，它得到的并不是编辑后的值</td>
</tr>
<tr>
<td>hideCol</td>
<td>colnameor[colnames]</td>
<td>jqGrid对象</td>
<td>如果参数为一个列名则隐藏此列，如果给定的是数组则隐藏指定的所有列。格式： [“name1”,”name2”]</td>
</tr>
<tr>
<td>remapColumns</td>
<td>permutation, updateCells, keepHeader</td>
<td>none</td>
<td>调整表格列的显示顺序,permutation为当前列的顺序，假如值是[1,0,2]，那么第一列就会在第二位显示。如果updateCells为ture则是对单元格数据进行重新排序，如果keepHeader为true则对header数据显示位置进行调整</td>
</tr>
<tr>
<td>resetSelection</td>
<td>none</td>
<td>jqGrid对象</td>
<td>选择或者反选行数据，在多选模式下也同样起作用</td>
</tr>
<tr>
<td>setCaption</td>
<td>caption</td>
<td>jqGrid对象</td>
<td>设置表格的标题</td>
</tr>
<tr>
<td>setCell</td>
<td>rowid,colname, data, class, properties</td>
<td>jqGrid对象</td>
<td>改变单元格的值。rowid：当前行id；colname：列名称，也可以是列的位置索引，从0开始；data：改变单元格的内容，如果为空则不更新；class：如果是string则会使用addClass方法将其加入到单元格的css中，如果是array则会直接加到style属性中；properties：设置单元格属性</td>
</tr>
<tr>
<td>setGridParam</td>
<td>object</td>
<td>jqGrid对象</td>
<td>设置grid的参数。有些参数的修改必须要重新加载grid才可以生效，这个方法可以覆盖事件</td>
</tr>
<tr>
<td>setGridHeight</td>
<td>new_height</td>
<td>jqGrid对象</td>
<td>动态改变grid的高度，只能对单元格的高度进行设置而不能对表格的高度进行动态修改。new_height：可以是象素值，百分比或者”auto”</td>
</tr>
<tr>
<td>setGridWidth</td>
<td>new_width,shrink</td>
<td>jqGrid对象</td>
<td>动态改变表格的宽度。new_width:表格宽度，象素值；shrink：true或者false，作用同shrinkToFit</td>
</tr>
<tr>
<td>setLabel</td>
<td>colname, data, class, properties</td>
<td>jqGrid对象</td>
<td>给指定列设置一个新的显示名称。colname：列名称，也可以是列的位置索引，从0开始；data：列显示名称，如果为空则不修改；class：如果是string则会使用addClass方法将其加入到单元格的css中，如果是array则会直接加到style属性中；properties：设置label的属性</td>
</tr>
<tr>
<td>setRowData</td>
<td>rowid,data, cssprop</td>
<td>成功true否则false</td>
<td>更新行的值，rowid为行id。data值格式：{name1:value1,name2: value2…} name为colModel中名称；cssprop：如果是string则会使用addClass方法将其加入到行的css中，如果是array或者对象则会直接加到style属性中</td>
</tr>
<tr>
<td>setSelection</td>
<td>rowid,onselectrow</td>
<td>jqGrid对象</td>
<td>选择或反选指定行。如果onselectrow为ture则会触发事件onSelectRow，onselectrow默认为ture</td>
</tr>
<tr>
<td>showCol</td>
<td>colname</td>
<td>jqGrid</td>
<td>显示列。colname可以是数组[“name1”,”name2”],但是name1或者name2必须是colModel中的name</td>
</tr>
<tr>
<td>trigger(“reloadGrid”)</td>
<td>none</td>
<td>jqGrid对象</td>
<td>重新加载当前表格，也会向服务器发起新的请求</td>
</tr>
<tr>
<td>updateColumns</td>
<td>none</td>
<td>none</td>
<td>同步表格的宽度，用在表格拖拽时，用法：var mygrid=jQuery(”#grid_id”)[0];mygrid.updateColumns();</td>
</tr>
</tbody>
</table>
<p>以上是jqGrid的绑定方法，一下是一些通用方法（相当于静态方法）。其使用方法为</p>
<pre lang="javascript">
<script>
...
jQuery.jgrid.jqGridFunction( parameter1,...parameterN );
...
</script>
jqGridFunction是一个函数。
parameter1,…parameterN 是对应的变量。
</pre>
<table>
<tr>
<td>函数名</td>
<td>参数</td>
<td>返回值</td>
<td>说明</td>
</tr>
<tr>
<td>ajaxOptions</td>
<td>空对象</td>
<td>none</td>
<td>这个函数可以改变jqgrid中用到的ajax请求参数，这个函数可以覆盖当前所有ajax请求设置。从3.6版本开始起有3个级别的ajax设置：第一个级别就是在模块中设置ajax请求；第二个级别就是通过此函数设置；第三级别的设置是控制全局ajax请求的设置：jQuery.extend(jQuery.ajax({method<br />
								specific options}, ajaxOptions,<br />
								ThirdLevelajaxSettinds)); 当然我们也可以单独设置ajax的参数</td>
</tr>
<tr>
<td>jqID</td>
<td>string</td>
<td>解析后的string</td>
<td>转义字符串，把两个反斜杠(\\)转化为单个反斜杠(\)</td>
</tr>
<tr>
<td>jgrid.htmlDecode</td>
<td>string</td>
<td>转换后string</td>
<td>把转码后的字符串还原</td>
</tr>
<tr>
<td>jgrid.htmlEncode</td>
<td>string</td>
<td>编码后的string</td>
<td>把字符串编码</td>
</tr>
<tr>
<td>jgrid.format</td>
<td>string</td>
<td>格式化后string</td>
<td>简单字符串模板。用法：Example jQuery.jqgformat(“Please<br />
								enter a value between {0} and {1}.”, 4result<br />
								: “Please enter a value between 4 and 8.”</td>
</tr>
<tr>
<td>jgrid.getCellIndex</td>
<td>cell</td>
<td>index</td>
<td>这个方法是用来修复在ie7里的一个bug</td>
</tr>
<tr>
<td>jgrid.stringToDoc</td>
<td>xmlstring</td>
<td>xmlDoc</td>
<td>把xmlstring转换为dom对象</td>
</tr>
<tr>
<td>jgrid.stripHtml</td>
<td>content</td>
<td>new_content</td>
<td>去掉html标签返回标签中内容</td>
</tr>
<tr>
<td>jgrid.parse</td>
<td>jsonstring</td>
<td>对象</td>
<td>把一个jsonstring转换为json对象，</td>
</tr>
</table>
<p></p>
<table border="1">
<tr>
<td>方法名</td>
<td>参数</td>
<td>返回值</td>
<td>说明</td>
</tr>
<tr>
<td>filterGrid</td>
<td>grid_id,params</td>
<td>HTML对象</td>
<td>构造jqGrid的查询界面。grid_id:表格id；params：参数</td>
</tr>
<tr>
<td>filterToolbar</td>
<td>params</td>
<td>jqGrid对象</td>
<td>同上。不同的是搜索输入框在header层下方</td>
</tr>
<tr>
<td>getColProp</td>
<td>colname</td>
<td>array{}</td>
<td>返回指定列的属性集合。name为colModel中名称</td>
</tr>
<tr>
<td>GridDestroy</td>
<td>grid_id</td>
<td>成功true否则false</td>
<td>从dom上删除此grid</td>
</tr>
<tr>
<td>GridUnload</td>
<td>grid_id</td>
<td>成功true否则false</td>
<td>跟GridDestroy不同的是table对象跟pager对象并不会被删除，以便下次使用</td>
</tr>
<tr>
<td>setGridState</td>
<td>state</td>
<td>jqGrid对象</td>
<td>设置grid的状态，显示或者隐藏。这个方法不会触发onHeaderClick 事件。</td>
</tr>
<tr>
<td>setColProp</td>
<td>colname, properties</td>
<td>jqGrid对象</td>
<td>设置新的属性，对于动态改变列属性是非常有用的，但是有些属性的修改并不会起效。用法：jQuery(”#grid_id”).setColProp(&#39;colname&#39;,{editoptions:{value:“True:False”}});
								</td>
</tr>
<tr>
<td>sortGrid</td>
<td>colname, reload</td>
<td>jqGrid对象</td>
<td>按指定列进行排序。效果同setGridParam({sortname:&#39;myname&#39;}).trigger(&#39;reloadGrid&#39;).<br />
								如果reload为true则会重新加载数据</td>
</tr>
<tr>
<td>updateGridRows</td>
<td>data,rowidname,jsonreader</td>
<td>成功true否则为false</td>
<td>
								修改表格中某行的数据，data数据格式：[{name:value,name1:value1…},<br />
								{name:value,name2:value2…}]，name为colModel中的名称；rowidname某行的名称。jsonreader：boolean值，默认false。如果为true则是定义数据的格式，data的值并不是name：value形式而只是value</td>
</tr>
</table>
<p>以上来自a3mao.javaeye.com</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-base-study-6.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jqGrid基础学习：5jqGrid中事件的使用</title>
		<link>http://www.mrzeng.com/post/jqgrid-base-study-5.html</link>
		<comments>http://www.mrzeng.com/post/jqgrid-base-study-5.html#comments</comments>
		<pubDate>Mon, 08 Feb 2010 01:54:44 +0000</pubDate>
		<dc:creator>zenghuashui</dc:creator>
				<category><![CDATA[jqGrid]]></category>

		<guid isPermaLink="false">http://www.mrzeng.com/?p=179</guid>
		<description><![CDATA[jqGrid中提供了丰富的事件。主要如下，这些只要看看就好。部分用不到，部分要到再详解。 Event Parameters Description afterInsertRow rowid rowdata rowelem This event fires after every inserted row. rowid is the id of the inserted row rowdata is an array of the data to be inserted into the row. This is array of type name: value, where the name is a name from colModel rowelem is the element [...]]]></description>
			<content:encoded><![CDATA[<p>jqGrid中提供了丰富的事件。主要如下，这些只要看看就好。部分用不到，部分要到再详解。</p>
<p><span id="more-179"></span></p>
<table border="1">
<tbody>
<tr>
<th>Event</th>
<th>Parameters</th>
<th>Description</th>
</tr>
<tr>
<td>afterInsertRow</td>
<td>rowid<br />
rowdata<br />
rowelem</td>
<td>This event fires after every inserted row.<br />
<em>rowid</em> is the id of the inserted row<br />
<em>rowdata</em> is an array of the data to be inserted into the row. This is array of type name: value, where the name is a name from colModel<br />
<em>rowelem</em> is the element from the response. If the data is xml this is the xml element of the row; if the data is json this is array containing all the data for the row<br />
Note: this event does not fire if gridview option is set to true<span style="color: #ff0000;">当插入每行时触发。rowid插入当前行的id；rowdata插入行的数据，格式为name: value，name为colModel中的名字。rowelem是从服务器返回的数据，如果数据时xml则返回该行的xml数据，如果是json，就返回这行关于这行的所有数据的数组。</span></td>
</tr>
<tr>
<td>beforeRequest</td>
<td>none</td>
<td>This event fire before requesting any data. Also does not fire if datatype is function<span style="color: #ff0000;">向服务器端发起请求之前触发此事件但如果datatype是一个function时例外</span></td>
</tr>
<tr>
<td>beforeSelectRow</td>
<td>rowid, e</td>
<td>This event fire when the user click on the row, but before select them.<br />
<em>rowid</em> is the id of the row.<br />
<em>e</em> is the event object<br />
This event should return boolean true or false. If the event return true the selection is done. If the event return false the row is not selected and any other action if defined does not occur.<span style="color: #ff0000;">当用户点击当前行在未选择此行时触发。rowid：此行id；e：事件对象。返回值为ture或者false。如果返回true则选择完成，如果返回false则不会选择此行也不会触发其他事件</span></td>
</tr>
<tr>
<td>gridComplete</td>
<td>none</td>
<td>This fires after all the data is loaded into the grid and all other processes are complete. Also the event fires independent from the datatype parameter and after sorting paging and etc.<span style="color: #ff0000;">当表格所有数据都加载完成而且其他的处理也都完成时触发此事件，排序，翻页同样也会触发此事件</span></td>
</tr>
<tr>
<td>loadBeforeSend</td>
<td>xhr</td>
<td>A pre-callback to modify the XMLHttpRequest object (<em>xhr</em>) before it is sent. Use this to set custom headers etc. The XMLHttpRequest is passed as the only argument.<span style="color: #ff0000;">在发送之前设置一个预先的回调函数来改变xhr对象，使用该方法可以社智能光自定义headers。xhr对象做为一个参数来传递</span></td>
</tr>
<tr>
<td>loadComplete</td>
<td>xhr</td>
<td>This event is executed immediately after every server request.<br />
<em>xhr</em> XMLHttpRequest object<span style="color: #ff0000;">当从服务器返回响应时执行，xhr：XMLHttpRequest 对象</span></td>
</tr>
<tr>
<td>loadError</td>
<td>xhr,<br />
status,<br />
error</td>
<td>A function to be called if the request fails. The function gets passed three arguments: The XMLHttpRequest object (<em>xhr</em>), a string describing the type of error (<em>satus</em>) that occurred and an optional exception object (<em>error</em>), if one occurred.<span style="color: #ff0000;">如果请求服务器失败则调用此方法。xhr：XMLHttpRequest 对象；satus：错误类型，字符串类型；error：exception对象</span></td>
</tr>
<tr>
<td>onCellSelect</td>
<td>rowid,<br />
iCol,<br />
cellcontent,<br />
e</td>
<td>Fires when we click on particular cell in the grid.<br />
<em>rowid</em> is the id of the row<br />
<em>iCol</em> is the index of the cell,<br />
<em>cellcontent</em> is the content of the cell,<br />
<em>e</em> is the event object element where we click.<br />
(Note that this available when we not use cell editing module and is disabled when using cell editing).<span style="color: #ff0000;">当点击单元格时触发。rowid：当前行id；iCol：当前单元格索引；cellContent：当前单元格内容；e：event对象</span></td>
</tr>
<tr>
<td>ondblClickRow</td>
<td>rowid,<br />
iRow,<br />
iCol,<br />
e</td>
<td>Raised immediately after row was double clicked.<br />
<em>rowid</em> is the id of the row,<br />
<em>iRow</em> is the index of the row (do not mix this with the rowid),<br />
<em>iCol</em> is the index of the cell.<br />
<em>e</em> is the event object<span style="color: #ff0000;">双击行时触发。rowid：当前行id；iRow：当前行索引位置；iCol：当前单元格位置索引；e:event对象</span></td>
</tr>
<tr>
<td>onHeaderClick</td>
<td>gridstate</td>
<td>Fire after clicking to hide or show grid (hidegrid:true);<br />
<em>gridstate</em> is the state of the grid &#8211; can have two values &#8211; visible or hidden<span style="color: #ff0000;">当点击显示/隐藏表格的那个按钮时触发；gridstate：表格状态，可选值：visible or hidden</span></td>
</tr>
<tr>
<td>onPaging</td>
<td>pgButton</td>
<td>This event fires after click on [page button] and before populating the data. Also works when the user enters a new page number in the page input box (and presses [Enter]) and when the number of requested records is changed via the select box. To this event we pass only one parameter <em>pgButton</em> See pager.<br />
If this event return &#8216;stop&#8217; the processing is stopped and you can define your own custom pagging<span style="color: #ff0000;">点击翻页按钮填充数据之前触发此事件，同样当输入页码跳转页面时也会触发此事件</span></td>
</tr>
<tr>
<td>onRightClickRow</td>
<td>rowid,<br />
iRow,<br />
iCol,<br />
e</td>
<td>Raised immediately after row was right clicked.<br />
<em>rowid</em> is the id of the row,<br />
<em>iRow</em> is the index of the row (do not mix this with the rowid),<br />
<em>iCol</em> is the index of the cell.<br />
<em>e</em> is the event object.<br />
Note &#8211; this event does not work in Opera browsers, since Opera does not support oncontextmenu event<span style="color: #ff0000;">在行上右击鼠标时触发此事件。rowid：当前行id；iRow：当前行位置索引；iCol：当前单元格位置索引；e：event对象。此事件不支持opera游览器</span></td>
</tr>
<tr>
<td>onSelectAll</td>
<td>aRowids,<br />
status</td>
<td>This event fires when multiselect option is true and you click on the header checkbox.<br />
<em>aRowids</em> array of the selected rows (rowid&#8217;s).<br />
<em>status</em> &#8211; boolean variable determining the status of the header check box &#8211; true if checked, false if not checked.<br />
Note that the aRowids alway contain the ids when header checkbox is checked or unchecked.<span style="color: #ff0000;">multiselect为ture，且点击头部的checkbox时才会触发此事件。aRowids：所有选中行的id集合，为一个数组。status：boolean变量说明checkbox的选择状态，true选中false不选中。无论checkbox是否选择，aRowids始终有值</span></td>
</tr>
<tr>
<td>onSelectRow</td>
<td>rowid,<br />
status</td>
<td>Raised immediately after row was clicked.<br />
<em>rowid</em> is the id of the row,<br />
<em>status</em> is the status of the selection. Can be used when multiselect is set to true. true if the row is selected, false if the row is deselected.<span style="color: #ff0000;">选择行时触发此事件。rowid：当前行id；status：选择状态，当multiselect 为true时此参数才可用</span></td>
</tr>
<tr>
<td>onSortCol</td>
<td>index,<br />
iCol,<br />
sortorder</td>
<td>Raised immediately after sortable column was clicked and before sorting the data.<br />
<em>index</em> is the index name from colModel,<br />
<em>iCol</em> is the index of column,<br />
<em>sortorder</em> is the new sorting order &#8211; can be &#8216;asc&#8217; or &#8216;desc&#8217;.<br />
If this event return &#8216;stop&#8217; the sort processing is stopped and you can define your own custom sorting<span style="color: #ff0000;">当点击排序列但是数据还未进行变化时触发此事件。index：name在colModel中位置索引；iCol：当前单元格位置索引；sortorder：排序状态：desc或者asc</span></td>
</tr>
<tr>
<td>resizeStart</td>
<td>event, index</td>
<td>Event which is called when we start resize a column. <em>event</em> is the event object, <em>index</em> is the index of the column in colModel.<span style="color: #ff0000;">当开始改变一个列宽度时触发此事件。event：event对象；index：当前列在colModel中位置索引</span></td>
</tr>
<tr>
<td>resizeStop</td>
<td>newwidth, index</td>
<td>Event which is called after the column is resized. <em>newwidth</em> is the is the new width of the column , <em>index</em> is the index of the column in colModel.<span style="color: #ff0000;">当列宽度改变之后触发此事件。newwidth：列改变后的宽度；index：当前列在colModel中的位置索引</span></td>
</tr>
<tr>
<td>serializeGridData</td>
<td>postData</td>
<td>If set this event can serialize the data passed to the ajax request. The function should return the serialized data. This event can be used when a custom data should be passed to the server &#8211; e.g &#8211; JSON string, <acronym title="Extensible Markup Language">XML</acronym> string and etc.<br />
To this event we pass the postData array.<span style="color: #ff0000;">向服务器发起请求时会把数据进行序列化，用户自定义数据也可以被提交到服务器端</span></td>
</tr>
</tbody>
</table>
<p>以上翻译部分来自a3mao.javaeye.com</p>
<h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://www.mrzeng.com/post/jqgrid-formater-2.html" title="jqGrid进阶教程：3、jqGrid的数据格式化二">jqGrid进阶教程：3、jqGrid的数据格式化二</a><br /><small>jqGrid是非常强大的，除了上一讲提到的预置的格式化外，还提供自定义的格式化方法，这种方法也是我比较喜欢的方法。
我们接上面的例子


$("#grid_id").jqGrid({
...
   colModel : [ {name:'sex', edittype:'select', editoptions:{value:"1:男;2:女"}} ... ],
...
});
...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-example-download.html" title="jqGrid例子文件下载">jqGrid例子文件下载</a><br /><small>最近慵懒了很多，很少来上面博一博，发下jqGrid的例子的全部文件。
jqGrid
由于文件太大，删掉了所有的jar包，jar是整合struts2.1+spring2.5+hibernate3.2...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-css.html" title="jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法">jqGrid进阶教程：1、jqGrid的样式无法正确显示的原因和解决办法</a><br /><small>jqGrid引入后，执行，常常会碰到css无法像官方的demo一样正常显示，特别是字体还有一些弹出框，

例如
[caption id="attachment_407" align="alignnone" width="300" caption="CSS变样"][/caption]
这种问题的原因多半是因为html的标准问题，即其写法为




如果要让样式正常，要采用写法如下...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-11.html" title="jqGrid基础学习：11jqGrid的查询时和后台的交互">jqGrid基础学习：11jqGrid的查询时和后台的交互</a><br /><small>jqGrid查询时和后台交互是一个比较棘手的问题，因为发送过来的数据不规则。


单字段
我们通过Firefox的firebug来进行调试，我们发现提交搜索请求后，向后台发送的参数如下
[caption id="attachment_382" align="alignnone" width="300" caption="单字段同后台交互"][/caption]
由此，我们看出单字段查询...</small></li><li><a href="http://www.mrzeng.com/post/jqgrid-base-study-10.html" title="jqGrid基础学习：10jqGrid的多字段查询">jqGrid基础学习：10jqGrid的多字段查询</a><br /><small>多字段查询就是高级查询，在jqGrid中，高级查询的麻烦在于同后台的交互。

[caption id="attachment_379" align="alignnone" width="718" caption="jqGrid多字段查询"][/caption]

启用多条件查询的方法，是加上.searchGrid({multipleSearch:true});    即可。

    ...</small></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.mrzeng.com/post/jqgrid-base-study-5.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

