六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 791|回复: 0

jQuery LigerUI 表格LigerGrid 结合 ASP.NET MVC 显示数据-it论坛

[复制链接]
 楼主| 发表于 2013-12-18 11:08:53 | 显示全部楼层 |阅读模式
jQuery LigerUI 表格LigerGrid 结合 ASP.NET MVC 显示数据-it论坛
准备工作。创建MVC项目,拷贝LIGERUI库到Web程序中。一,准备工作使用开发工具:Microsoft Visual Studio 2010
使用插件版本: jQuery 1.4.1  、 jQuery LigerUI 1.1.7
二,创建MVC项目

三,下载最新版的ligerui,并拷贝到web的根目录下载地址:http://ligerui.googlecode.com/






增加视图和Action,引入jQuery库和ligerUI库的引用,模板页中增加视图的链接一,增加视图


二,增加Action

三,引入jQuery库和ligerui的引用


四:模板页增加视图的链接


准备数据结构(ligerGrid的调用) 和数据源(增加一个Action,返回JSON格式)一,编写JS代码调用ligerGrid

这里要注意一下URL的格式 : /Home/GetData

二,准备数据源(增加一个Action,返回JSON格式)

三,效果

如何分页和排序。一,ligerGrid服务器端分页的原理可以利用firebug来调试,可以查看到grid加载分页数据的时候,会往服务器传几个数据:

那么在后台我们需要根据这几个参数返回grid适合的数据:

二,如何使用MVC Action接收并返回数据:
  1. public ActionResult GetData2()
  2.         {
  3.             //排序的字段名
  4.             string sortname = Request.Params["sortname"];
  5.             //排序的方向
  6.             string sortorder = Request.Params["sortorder"];
  7.             //当前页
  8.             int page = Convert.ToInt32(Request.Params["page"]);
  9.             //每页显示的记录数
  10.             int pagesize = Convert.ToInt32(Request.Params["pagesize"]);

  11.             IList<Node> list = new List<Node>();
  12.             var total = 1000;
  13.             for (var i = 0; i < total; i++)
  14.             {
  15.                 list.Add(new Node()
  16.                 {
  17.                     id = i,
  18.                     name = "部门" + i,
  19.                     time = DateTime.Now
  20.                 });
  21.             }
  22.             //这里模拟排序操作
  23.             if (sortorder == "desc")
  24.                 list = list.OrderByDescending(c => c.id).ToList();
  25.             else
  26.                 list = list.OrderBy(c => c.id).ToList();

  27.             IList<Node> targetList = new List<Node>();
  28.             //这里模拟分页操作
  29.             for (var i = 0; i < total; i++)
  30.             {
  31.                 if (i >= (page - 1) * pagesize && i < page * pagesize)
  32.                 {
  33.                     targetList.Add(list[i]);
  34.                 }
  35.             }
  36.             var griddata = new { Rows = targetList, Total = total };
  37.             return Json(griddata);
  38.         }
复制代码
三,前台调用
四,效果


源码下载下载地址:GridMvcApp.7z
分类: 02.LigerUI
摘自:http://www.cnblogs.com/leoxie2011/archive/2012/03/06/2381720.html






该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表