网上找了好多人的方法发现都有问题发一个可用方便的

主要分三种情况 加载
1,loaddata 加载
2,datagrid 加载
3, url 加载

第一部分,datagrid加载

第二部分,点击 datagrid里面的跳转

第三部分,弹窗显示

首先MVC控制器初始数据

  1. public JsonResult Data()
  2. {
  3. var product = new[]
  4. {
  5. new { productid="FI-SW-01",unitcost=,status="P",listprice=,attr1="Large",itemid="EST-1"},
  6. new { productid="K9-DL-01",unitcost=,status="P",listprice=,attr1="Spotted Adult Female",itemid="EST-10"},
  7. new { productid="RP-SN-01",unitcost=,status="P",listprice=,attr1="Venomless",itemid="EST-11"},
  8. new { productid="RP-SN-01",unitcost=,status="P",listprice=,attr1="Rattleless",itemid="EST-12"},
  9. new { productid="RP-LI-02",unitcost=,status="P",listprice=,attr1="Green Adult",itemid="EST-13"},
  10. new { productid="FL-DSH-01",unitcost=,status="P",listprice=,attr1="Tailless",itemid="EST-14"},
  11. new { productid="FL-DSH-01",unitcost=,status="P",listprice=,attr1="With tail",itemid="EST-15"},
  12. new { productid="FL-DLH-02",unitcost=,status="P",listprice=,attr1="Adult Female",itemid="EST-16"},
  13. new { productid="FL-DLH-02",unitcost=,status="P",listprice=,attr1="Adult Male",itemid="EST-17"},
  14. new { productid="AV-CB-01",unitcost=,status="P",listprice=,attr1="Adult Male",itemid="EST-18"}
  15. };
  16.  
  17. return Json(new { total = product.Count(), rows = product }, JsonRequestBehavior.AllowGet);
  18. }

第一部分,1 loaddata 需要先预加载表格格式,在填充数据

  1. <table id="tt" title="Load Data" class="easyui-datagrid" style="width:700px;height:250px"
  2. iconCls="icon-save" pagination="true">
  3. <thead>
  4. <tr>
  5. <th field="itemid" width="80">Item ID</th>
  6. <th field="productid" width="120">Product ID</th>
  7. <th field="listprice" width="80" align="right">List Price</th>
  8. <th field="unitcost" width="80" align="right">Unit Cost</th>
  9. <th field="attr1" width="250">Attribute</th>
  10. <th field="status" width="60" align="center">Stauts</th>
  11. </tr>
  12. </thead>
  13. </table>
  1. function dd()
  2. {
  3. $.ajax(
  4. {
  5. type: 'post',
  6. url: '@Url.Action("data","home")',
  7. data: {
  8. url: 'hello',
  9. },
  10. dataType: 'json',
  11. success: function (data, stutas, xhr) {
  12. $('#tt').datagrid("loadData", data)
  13. },
  14. error: function (xhr, textStatus, data) {
  15. alert(data);
  16. }
  17. });
  18. };

2 datagrid 加载

  1. <table id="Cse_Bespeak_Log" class="easyui-datagrid" style="width: auto; height: 350px;"></table>
  1. $("#Cse_Bespeak_Log").datagrid({
  2. url: "@Url.Action("data", "home")",
  3. iconCls: "icon-add",
  4. fitColumns: false,
  5. loadMsg: "数据加载中......",
  6. pagination: true,
  7. rownumbers: true,
  8. nowrap: false,
  9. showFooter: true,
  10. singleSelect: true,
  11. pageList: [100, 50, 20, 10],
  12.  
  13. columns: [[
  14. {
  15. field: 'itemid', title: '编号', width: 50, align: 'center',
  16. formatter: function (value, row, index) {
  17.  
  18. return " <a href='javascript:void(0)' onclick='return LoadUserInfo()'>" + value + "</a>";
  19. }
  20. },
  21. {
  22. field: 'productid', title: '用户名', width: 150, align: 'center',
  23. },
  24. {
  25. field: 'listprice', title: '姓名', width: 150, align: 'center',
  26. },
  27. {
  28. field: 'unitcost', title: '操作', width: 100, align: 'center',
  29. },
  30. {
  31. field: 'attr1', title: '操作', width: 100, align: 'center',
  32. },
  33. {
  34. field: 'status', title: '操作', width: 100, align: 'center',
  35. }]]
  36.  
  37. })

3.url加载

  1. <table id="tt" title="Load Data" class="easyui-datagrid" style="width:700px;height:250px"
  2. url="@Url.Action("data","home")"
  3. iconCls="icon-save" pagination="true">
  4. <thead>
  5. <tr>
  6. <th field="itemid" width="80">Item ID</th>
  7. <th data-options="field:'productid',width:180,formatter: rowformater" field="productid" width="120">Product ID</th>
  8. <th field="listprice" width="80" align="right">List Price</th>
  9. <th field="unitcost" width="80" align="right">Unit Cost</th>
  10. <th field="attr1" width="250">Attribute</th>
  11. <th field="status" width="60" align="center">Stauts</th>
  12. </tr>
  13. </thead>
  14. </table>
  1. var pager = $('#tt').datagrid('getPager'); // get the pager of datagrid
  2. pager.pagination({
  3. showPageList: false,
  4. buttons: [{
  5. iconCls: 'icon-search',
  6. handler: function () {
  7. alert('search');
  8. }
  9. }, {
  10. iconCls: 'icon-add',
  11. handler: function () {
  12. alert('add');
  13. }
  14. }, {
  15. iconCls: 'icon-edit',
  16. handler: function () {
  17. alert('edit');
  18. }
  19. }],
  20. onBeforeRefresh: function () {
  21. alert('before refresh');
  22. return true;
  23. }
  24. });
  25.  
  26. });

第二部分datagird里面加跳转

1.

  1. <th data-options="field:'productid',width:180,formatter: rowformater" field="productid" width="120">Product ID</th>
  1. function rowformater(value, row, index) {
  2. return "<a href='" + row.id + "' target='_blank'>操作</a>";
  3. };

2已经在上第一部分2中

第三部分,弹窗显示 预制一个table 加载数据在open

  1. <div id="dlg" class="easyui-dialog" style="width: 1000px; height: 350px;"
  2. data-options="closed:true,buttons:'#dlg-buttons'">
  3. <table id="datagrid" class="easyui-datagrid" style="width:600px;height:350px">
  4.  
  5. </table>
  6. </div>
  1. function LoadUserInfo() {
  2.  
  3. /*获取选中行*/
  4. //var row = $('#Cse_Bespeak_Log').datagrid('getSelected'); //获取选中行
  5.  
  6. $("#datagrid").datagrid({
  7. url: "@Url.Action("data1", "home")",
  8. iconCls: "icon-add",
  9. fitColumns: false,
  10. loadMsg: "数据加载中......",
  11. pagination: true,
  12. rownumbers: true,
  13. nowrap: false,
  14. showFooter: true,
  15. singleSelect: true,
  16. pageList: [100, 50, 20, 10],
  17.  
  18. columns: [[
  19. {
  20. field: 'itemid', title: '编号', width: 50, align: 'center',
  21. formatter: function (value, row, index) {
  22.  
  23. return " <a href='javascript:void(0)' onclick='return LoadUserInfo()'>"+ value +"</a>";
  24. }
  25. },
  26. {
  27. field: 'productid', title: '用户名', width: 150, align: 'center',
  28. },
  29. {
  30. field: 'listprice', title: '姓名', width: 150, align: 'center',
  31. },
  32. {
  33. field: 'unitcost', title: '操作', width: 100, align: 'center',
  34. },
  35. {
  36. field: 'attr1', title: '操作', width: 100, align: 'center',
  37. },
  38. {
  39. field: 'status', title: '操作', width: 100, align: 'center',
  40. }]]
  41.  
  42. })
  43.  
  44. $('#dlg').window('open'); //弹出这个dialog框
  45. };

https://www.cnblogs.com/baiyangyuanzi/p/6702742.html?utm_source=itdadao&utm_medium=referral

EasyUI datagrid 数据加载的更多相关文章

  1. easyui datagrid 异步加载数据时滚动条有时会自动滚到最底部的问题

    在使用easyui 的datagrid异步加载数据时发现滚动条有时会自动滚到最底部.经测试发现,如果加载数据前没有选中行则不会出现这个问题.这样我们可以在重新异步加载数据前取消选中行就可以避免这个问题 ...

  2. easyui datagrid 动态加载数据 渲染问题,表格错位问题

    $('#dg').datagrid({ url:'datagrid_data.json', columns:[[ {field:'code',title:'Code',width:100}, {fie ...

  3. jquery easyui datagrid 远程加载数据----把主键渲染为值遇到的问题及解决方案

    起因:数据库中一些字段存的是代表具体值的数字,需要渲染为具体值 monggodb中的字典 mysql中存放的值为:expertin代表教练擅长的搏击技能 jquery easyui中的相关代码如下:用 ...

  4. jquery easyui datagrid 远程加载数据----javascript法

    jquery easyui有三种办法生成datagrid(数据网格),本篇专门讨论javascript借助jquey easy ui实现的方式 html部分 <main role="m ...

  5. EasyUI datagrid easyui datagrid +dialog 加载 可直接运行 七

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...

  6. easyui datagrid onLoadSuccess加载两次。。

    今天使用EasyUI的datagrid时发现首次打开页面时onLoadSuccess方法执行了两次.后来发现主要问题是datagrid被初始化了两次.主要原因是一开始html中声明了dg为easyui ...

  7. EasyUI datagrid动态加载json数据

    最近做一个项目,要求是两张张表可能查找出10多种不同的结果集. 如果想只用一个表格就把全部的结果不同的显示出来那么就肯定不同使用固定的字段名字,要通过动态加载后台返回来的数据把它显示出来就必须动态加载 ...

  8. EasyUI datagrid 动态加载表头和数据

    首先返回到页面的需要是JSON数据: 第一步: 遍历表头,插入到array中 for (var i = 0; i < jsonObj.title.length; i++) { //把返回的数据封 ...

  9. 【第一篇】说说MVC+EF easyui dataGrid 动态加载分页表格

    首先上javascript的代码 <script type="text/javascript"> $(function () { LoadGrid(); }) //加载 ...

随机推荐

  1. mips编译器交叉编译openssl

    1.下载源码: git clone https://github.com/openssl/openssl.git 2. 配置生成Makefile ./config  no-asm shared --p ...

  2. iframe子父页面函数互相调用

    1.iframe子页面调用父页面js函数 子页面调用父页面函数只需要写上window.praent就可以了.比如调用a()函数,就写成: window.parent.a();  子页面取父页面中的标签 ...

  3. [Leetcode 739]*还有几天会升温 Daily Temperatures

    [题目] Given a list of daily temperatures T, return a list such that, for each day in the input, tells ...

  4. pytorch加载和保存模型

    在模型完成训练后,我们需要将训练好的模型保存为一个文件供测试使用,或者因为一些原因我们需要继续之前的状态训练之前保存的模型,那么如何在PyTorch中保存和恢复模型呢? 方法一(推荐): 第一种方法也 ...

  5. 第一章 使用功能测试协助安装Django

    1.1 第一个简单的测试--断言 from selenium import webdriver browser = webdriver.Firefox() browser.get('http://lo ...

  6. html回顾随笔JS(*^__^*)

    ---恢复内容开始--- map遍历 function b(){ var week = new Map(); week.set("Mon","星期一"); we ...

  7. nio的简单学习

    参考链接: http://www.iteye.com/magazines/132-Java-NIO https://www.cnblogs.com/xiaoxi/p/6576588.html http ...

  8. requery.js使用姿势

    最近在看requerjs,现在来总结下自己的收获,有不对的地方,望大家指正! 1.首先介绍下requirejs,引用中文官网http://www.requirejs.cn的一句话,requirejs是 ...

  9. LimeSDR Getting Started Quickly | LimeSDR上手指南

    0x00 概览 LimeSDR部分特性: USB 3.0 : 4 x Tx 发射天线接口 6 x Rx 接收天线接口: 可用于Wi-Fi, GSM, UMTS, LTE, LoRa, Bluetoot ...

  10. CHERRY G80 3000L 使用一月有感

    就是楼上这家伙.. 都说程序猿用的最多的除了自己的右手就是键盘了.- - SO一个好的键盘必定会令写码的速度提升. 在TB和JD上选择许久,在青轴,红轴,黑轴,茶轴间难以抉择. 最后终于敲定: CHE ...