zoukankan      html  css  js  c++  java
  • table.appand(行数据) datagrid分页

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Mvc5.Models;
    
    namespace Mvc5.Controllers
    {
        public class HomeController : Controller
        {
            BookShopPlusEntities db = new BookShopPlusEntities();
    
            public ActionResult Index()
            {
                //控制器在启动index方法时,视图还没加载,Request.Params["page"]的值是空的
                if (Request.Params["page"]==null)
                {
                    return View();
                }
                else
                {
                    //获取客户端的请求参数:page是第几页
                    int pid = Convert.ToInt16(Request.Params["page"]);
                    //获取客户端的请求参数:size是每页几条数据
                    int size = Convert.ToInt16(Request.Params["rows"]);
                    int count = db.Books.Count();//总行数
                    //获取分页数据
                    List<Books> list = db.Books.OrderBy(b=>b.Id).Skip((pid - 1) * size).Take(size).ToList();
                    //把集合转换转换成匿名类对象
                    var result = from b in list
                                 select new
                                 {
                                     Title = b.Title,
                                     Id = b.Id
                                 };
                    //发送json数据到客户端,如果视图页面用到easyui的表格,必须用total和rows属性名
                    return Json(new { total = count, rows = result }, JsonRequestBehavior.AllowGet);
                }
            }
    
        }
    }
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
        <link href="~/easyui/themes/icon.css" rel="stylesheet" />
        <link href="~/easyui/themes/default/easyui.css" rel="stylesheet" />
        <script src="~/easyui/jquery.min.js"></script>
        <script src="~/easyui/jquery.easyui.min.js"></script>
        <script src="~/easyui/locale/easyui-lang-zh_CN.js"></script>
        <script>
            /*
            $(function () {
                $("#tab").datagrid({
                    url: "/Home/Index",
                    columns: [[
                        { field: 'Title', title: '标题' }
                    ]],
                    singleSelect: true,
                    pagination: true,
                    pageSize: 10,
                    //设置分页时初始化条数选择大小
                    pageList: [5, 10, 15],
                    //设置分页时初始化页码
                    pageNumber: 1,
                    //设置分页工具栏的位置
                    pagePosition: "bottom"
                });
            });
            */
            $(function () {
                query(1,10);
            });
            function query(pid,size) {
                $.get("/Home/Index", { page: pid, rows: size }, function (result) {
                    $("#tab").empty();
                    $.each(result.rows, function (i, mod) {
                        var tr = "<tr><td>" + mod.Title + "</td></tr>";
                        $("#tab").append(tr);
                    });
                    $('#pager').pagination({
                        total: result.total,//总行数
                        pageSize: size,
                        pageNumber: pid,
                        onSelectPage: function (pagenum, pagesize) {
                            query(pagenum, pagesize);
                        },
                        onChangePageSize: function (pagenum, pagesize) {
                            query(pagenum, pagesize);
                        }
                    });
                }, "json");
            }
        </script>
    </head>
    <body>
        <table id="tab"></table>
        <div id="pager" style="background-color:aquamarine"></div>
    </body>
    </html>
  • 相关阅读:
    HDU 1556 Color the ball【树状数组】
    HDU 3015 Disharmony Trees 【 树状数组 】
    POJ 1990 MooFest【 树状数组 】
    codeforces 493 C Vasya and Basketball
    12、Decorator 装饰器 模式 装饰起来美美哒 结构型设计模式
    11、Composite 组合模式 容器与内容的一致性(抽象化) 结构型设计模式
    10、Strategy 策略模式 整体地替换算法 行为型模式
    9、Bridge 桥梁模式 将类的功能层次结构与实现层结构分离 结构型设计模式
    读源码从简单的集合类之ArrayList源码分析。正确认识ArrayList
    8、Builder 建造者模式 组装复杂的实例 创造型模式
  • 原文地址:https://www.cnblogs.com/yiran123456/p/5596764.html
Copyright © 2011-2022 走看看