由于jqGrid功能强大,配置比较复杂,在第一个例子中,对于jqGrid的配置参数没有进行什么解释。从现在开始,会陆续介绍jqGrid的参数。这 些参数的详细介绍请查看官方文档。由于本人英语水平有限,翻译不好,请多原谅。(为了保证连贯性,翻译时引用了 http://a3mao.iteye.com,在此感谢。但在他的基础上增加了一些内容。)
a3mao永久域名 http://a3mao.iteye.com
上有很多jqGrid的API,大家可以查看。
在$("#tableId").jqGrid(optional);中,optional对象包含如下的属性:(属性按字母顺序排列)
另外
http://a3mao.iteye.com 还列出了常用的参数。如下:
另外,“是否可以被修改”的意思是:在表格创建后,参数是否能够或不能够被修改。换言之,在表格中的初始默认值能否被修改。
设置全局参数:
有时,我们想改变参数的默认值,且希望这种改变能够同时运用于多个表格。此时,我们可以使用jQuery的extend函数实现。
这里给一个例子:假设你想有一个行交替变色的表格,且希望所有的表格都是如此,并且,你不想每次(每构建一个表格)都配置相同的参数。这时你可以使用这种方式,只需配置一次即可。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" xml:lang ="en" lang ="en" > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < title >My First Grid </title> < link rel ="stylesheet" type ="text/css" media ="screen" href ="css/ui-lightness/jquery-ui-1.7.1.custom.css" /> < link rel ="stylesheet" type ="text/css" media ="screen" href ="css/ui.jqgrid.css" /> < style > html, body { margin: 0; padding: 0; font-size: 75%; } </style> < script src ="js/jquery-1.3.2.min.js" type ="text/javascript" > </script> < script src ="js/i18n/grid.locale-en.js" type ="text/javascript" > </script> < script src ="js/jquery.jqGrid.min.js" type ="text/javascript" > </script> < script type ="text/javascript" > // Here we set a globally the altRows option jQuery.extend(jQuery.jgrid.defaults, { altRows:true }); </script> < script type ="text/javascript" > jQuery(document).ready(function(){ jQuery("#list").jqGrid({ url:'example.php', ...
你也可以增加其他你想设置的参数。
覆盖全局参数:
在上面的例子中,我们学习了如何为你的应用程序中所有的表格设置共用的参数。然而,有些表格可能需要用其他的参数值,即需要对我们上,面设置的全局参数进行改变,以用于特定的表格。这时,我们可以把相应的参数改过来,即在特定的表格重新配置一次相应的属性。例如:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" xml:lang ="en" lang ="en" > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < title >My First Grid </title> < link rel ="stylesheet" type ="text/css" media ="screen" href ="css/ui-lightness/jquery-ui-1.7.1.custom.css" /> < link rel ="stylesheet" type ="text/css" media ="screen" href ="css/ui.jqgrid.css" /> < style > html, body { margin: 0; padding: 0; font-size: 75%; } </style> < script src ="js/jquery-1.3.2.min.js" type ="text/javascript" > </script> < script src ="js/i18n/grid.locale-en.js" type ="text/javascript" > </script> < script src ="js/jquery.jqGrid.min.js" type ="text/javascript" > </script> < script type ="text/javascript" > // Here we set a globally the altRows option jQuery.extend(jQuery.jgrid.defaults, { altRows:true }); </script> < script type ="text/javascript" > jQuery(document).ready(function(){ jQuery("#list").jqGrid({ url:'example.php', // here we do not want zebra for this grid altRows: false, ... 本文出自 “徐新华polaris” 博客,请务必保留此出处http://polaris.blog.51cto.com/1146394/260176 本文出自 51CTO.COM技术博客 |
个人签名
-------------------------------------