public
static
class
jqGridExtensions
{
public
static
string
jqGrid
<
T
>
(
this
HtmlHelper helper,
string
gridID,
string
caption,
string
url)
{
if
(gridID.Substring(
0
,
1
)
!=
"
#
"
)
gridID
=
"
#
"
+
gridID;
string
pagerID
=
string
.Format(
"
{0}_pager
"
, gridID);
StringBuilder sb
=
new
StringBuilder();
sb.AppendLine(
"
<script type=\
"
text
/
javascript\
"
>$(function(){
"
);
//
jQuery(document).ready(function() {
sb.AppendLine(
"
$('%%GRIDID%%').jqGrid({
"
.Replace(
"
%%GRIDID%%
"
, gridID));
//
jQuery("#list").jqGrid({
sb.AppendFormat(
"
url:'{0}',
"
, url);
//
url: '/Home/GridData/',
sb.Append(
"
datatype: 'json',mtype: 'GET',
"
);
//
datatype: 'json',mtype: 'GET',
sb.AppendFormat(
"
colNames:[{0}],
"
, GetColNames
<
T
>
());
sb.AppendFormat(
"
colModel:[{0}],
"
, GetColModel
<
T
>
());
sb.Append(
"
pager: '%%GRIDPAGERID%%',rowNum: 20,rowList: [10, 20, 50,100],
"
.Replace(
"
%%GRIDPAGERID%%
"
, pagerID));
sb.AppendFormat(
"
sortname:'{0}',sortorder: 'desc',
"
, GetSortField
<
T
>
());
sb.Append(
"
viewrecords: true,imgpath: '/themes/redmond/images',
"
);
sb.AppendFormat(
"
caption: '{0}'
"
, caption);
sb.Append(
"
});\n$('%%GRIDID%%').jqGrid('navGrid','%%GRIDPAGERID%%',{ edit: false, add: false, del: false });
"
.Replace(
"
%%GRIDID%%
"
, gridID).Replace(
"
%%GRIDPAGERID%%
"
, pagerID));
sb.Append(
"
});</script>\n
"
);
sb.AppendFormat(
"
<table id=\
"
{
0
}\
"
class=\
"
scroll\
"
cellpadding=\
"
0
\
"
cellspacing=\
"
0
\
"
></table>
"
, gridID.Substring(
1
));
sb.AppendFormat(
"
<div id=\
"
{
0
}\
"
class=\
"
scroll\
"
style=\
"
text
-
align:center;\
"
></div>
"
, pagerID.Substring(
1
));
sb.AppendLine();
return
sb.ToString();
}
}