<script type="text/javascript" language="javascript">
$(f_initGrid);
var grid;
function f_initGrid() {
grid = $("#maingrid").ligerGrid({
columns: [
{display:'前缀',name:'prefix',width: 100},
{ display: '编码', name: 'parts_no', width: 100},
{ display: '配件编码', name: 'prefix_parts_no', width: 100}],
url: 'Ashx/GetPartsList.ashx?Action=GetData', //一般处理程序
dataAction: 'server',//服务器排序
usePager:true
});
}
function f_search() {
grid.options.parms.where1 = "111"; //查询条件
grid.loadData(true);
}
</script>
Ashx代码:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string result=string.Empty;
string action = context.Request.Params["Action"];
string where = context.Request.Params["where1"];
string sortname = context.Request.Params["sortname"]; //排序名称
string sortorder = context.Request.Params["sortorder"]; //排序方式
string pageSize = context.Request.Params["pagesize"];
string page = context.Request.Params["page"];
int page_size_int = 10;
int page_int = 1;
if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(page))) int.TryParse(page, out page_int);
if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(pageSize))) int.TryParse(pageSize, out page_size_int);
page_int = page_int - 1;
IList<Node> list = new List<Node>();
string sql = "select prefix,parts_no,prefix_parts_no from sales_order_detail where ifnull(prefix,'')<>'' ";
if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(sortname)))
{
sql += " order by " + sortname + " " + sortorder;
}
else
{
sql += " order by create_date desc ";
}
sql += " limit " + page_int * page_size_int + "," + page_size_int;
DataTable dt = SalesCommon.QueryTable(sql);
for (var i = 0; i < dt.Rows.Count; i++)
{
list.Add(new Node()
{
prefix = dt.Rows[i]["prefix"].ToString(),
parts_no = dt.Rows[i]["parts_no"].ToString(),
prefix_parts_no = dt.Rows[i]["prefix_parts_no"].ToString()
});
}
sql = "select count(1) cnt from sales_order_detail where ifnull(prefix,'')<>''";
dt = SalesCommon.QueryTable(sql);
int page_count=0;
if (dt != null && dt.Rows.Count > 0) int.TryParse(SalesCommon.GetIsNullOrEmpty(dt.Rows[0]["cnt"]), out page_count);
var griddata = new { Rows = list, Total = page_count };
result = new JavaScriptSerializer().Serialize(griddata);
context.Response.Write(result);
context.Response.End();
}
//字段属性
class Node
{
public string prefix { get; set; }
public string parts_no { get; set; }
public string prefix_parts_no { get; set; }
}