1. ///**
  2. //*封装jquery get请求ajax
  3. //*author:叶明龙
  4. //*time:2012-12-10
  5. //*/
  6. function getAjax(url, para, fn) {
  7. if (typeof fn == "function") {
  8. if (para == undefined) {
  9. para = {};
  10. }
  11. $.get(url, para, function (data) {
  12. var obj = eval("(" + data + ")");
  13. fn.call(this, obj);
  14. })
  15. }
  16. }
  17.  
  18. /**
  19. *扩展Jquery方法创建LigerUI Grid
  20. *============================================
  21. *author:叶明龙
  22. *time:2014/06/21
  23. *
  24. *
  25. *============================================
  26. */
  27. ; (function ($) {
  28. $.fn.extend({
  29. createLigerGrid: function (opt) {
  30. var _t = $(this);
  31. var options = $.extend(true, {
  32. header: [],
  33. title: "",
  34. param: {},
  35. ajaxURL: "",
  36. ajaxMethod: "get",
  37. pageSize: 20,
  38. keyID: "",//主键
  39. editor: {
  40. url: "",
  41. para: [],
  42. width: 600,
  43. height: 600
  44. },
  45. success: function () { }
  46. }, opt);
  47. options.header.unshift({
  48. name: 'id', display: '操作', width: 100, isAllowHide: false,
  49. render: function (record, rowindex, value, column) {
  50. //this 这里指向grid
  51. //record 行数据
  52. //rowindex 行索引
  53. //value 当前的值,对应record[column.name]
  54. //column 列信息record[options.editor.para[0]]
  55. var _deleConfirm = "$.ligerDialog.confirm('确定删除?', function (yes) {";
  56. _deleConfirm += " if (yes) {";
  57. _deleConfirm += " getAjax('" + options.ajaxURL + "?type=delete&" + "id=" + record[options.editor.para[0]] + "',";
  58. _deleConfirm += "{";
  59. var _f = false;
  60. for (var pn in options.param) {
  61. if (_f)
  62. _deleConfirm += ",";
  63. _deleConfirm += "'" + pn + "':'" + options.param[pn] + "'";
  64. _f = true;
  65. }
  66. _deleConfirm += "}";
  67. _deleConfirm += ",function(data){";
  68. _deleConfirm += "if(data.success)$.ligerDialog.success('删除成功');else $.ligerDialog.error('删除失败');";
  69. _deleConfirm += "})";
  70. _deleConfirm += " }";
  71. _deleConfirm += " });";
  72. //onclick='eval(" + _deleConfirm + ");'
  73. return "<a href='javascript:;' onclick=\"" + _deleConfirm + "\">删除</a>&nbsp;&nbsp;<a href='javascript:;' onclick='$.ligerDialog.open({ title:\"修 改 " + record[options.editor.para[0]] + "\",width: " + options.editor.width + ", height: " + options.editor.height + ",url: \"" + options.editor.url + "?type=add\" });'>修改</a>";
  74. }
  75. });
  76. if (options.ajaxURL == "") {
  77. $.ligerDialog.warn("未填写请求ajaxURL,无法响应服务器请求数据响应");
  78. return false;
  79. }
  80.  
  81. var Grid = $(_t).ligerGrid({
  82. title: options.title,
  83. columns: options.header,
  84. pageSize: options.pageSize,
  85. method: options.ajaxMethod,
  86. url: options.ajaxURL,
  87. checkbox: true,
  88. toolbarShowInLeft: true,
  89. toolbar: {
  90. items: [{
  91. text: '添 加', click: function () {
  92. $.ligerDialog.open({ width: options.editor.width, height: options.editor.height, title: "添 加", url: options.editor.url + "?type=add" });
  93. }, icon: 'add'
  94. },
  95. {
  96. text: '删 除', click: function () {
  97. $.ligerDialog.confirm('确定删除?', function (yes) {
  98. if (yes) {
  99. var _Rows = Grid.getSelectedRows(), _keys = []
  100. for (var i = 0; i < _Rows.length; i++) {
  101. _keys.push(_Rows[i][options.editor.para[0]]);
  102. }
  103. getAjax(options.ajaxURL + "?type=delete&id=" + _keys.join(','), options.param, function (data) {
  104. if (data.success)
  105. $.ligerDialog.success('删除成功');
  106. else
  107. $.ligerDialog.error('删除失败');
  108. });
  109. }
  110. });
  111. }, icon: 'delete'
  112. }
  113. ]
  114. },
  115. root: "data",
  116. record: "total",
  117. width: '100%',
  118. height: '100%',
  119. heightDiff: -10,
  120. usePager: true,
  121. enabledSort: false,
  122. parms: options.param,
  123. pageSizeOptions: [5, 10, 15, 20],
  124. onCheckRow: function (checked, data, rowid, rowdata) {
  125.  
  126. },
  127. onLoaded: function (grid) {
  128. grid.toggleLoading(false);
  129. if (options.success)
  130. options.success($(_t).data("request_data"), grid);
  131. },
  132. onSuccess: function (data, grid) {
  133. $(_t).data("request_data", data);
  134. },
  135. onError: function (XMLHttpRequest, textStatus, errorThrown) {
  136. $.ligerDialog.warn("数据加载错误");
  137. }
  138. });
  139. return Grid;
  140. }
  141. });
  142. })(jQuery);

页面调用示例

  1. <!DOCTYPE html>
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title></title>
  7. <link rel="Stylesheet" type="text/css" href="/Content/css/Custom.css" />
  8. <link rel="stylesheet" type="text/css" href="/Content/js/LigerUI/skins/Aqua/css/ligerui-all.css" />
  9. <link rel="stylesheet" type="text/css" href="Content/js/LigerUI/skins/Gray/css/all.css" />
  10. <link rel="stylesheet" type="text/css" href="Content/js/LigerUI/skins/ligerui-icons.css" />
  11. <link href="/Content/css/default.css" rel="stylesheet" type="text/css" />
  12. <script type="text/javascript" src="/Content/js/jquery-1.7.2.min.js"></script>
  13. <script type="text/javascript" src="/Content/js/LigerUI/ligerui.all.js"></script>
  14. <script type="text/javascript" src="/Content/js/js2014.js"></script>
  15. <script src="/Content/js/jquery.cookie.js" type="text/javascript"></script>
  16. <script src="Content/js/JSON2.JS"></script>
  17. <script type="text/javascript" src="/Content/js/PUBLIC.JS"></script>
  18. <script type="text/javascript">
  19. $(document).ready(function () {
  20. $("#Grid").createLigerGrid({
  21. header: [{ display: '农作物名称', name: 'Goods_Name',isAllowHide:true },
  22. { display: '种植面积(亩)', name: 'Areas' }],
  23. param: {'flag':1},
  24. editor: {
  25. url: "",
  26. para: ["Goods_Name"]
  27. },
  28. ajaxURL: "/Pages/Hander/Highcharts.ashx"
  29. });
  30. });
  31. </script>
  32. </head>
  33. <body>
  34. <div id="Grid"></div>
  35. </body>
  36. </html>
  1. $(document).ready(function () {
  2. $("#Grid").createLigerGrid({
  3. header: [{ display: '农作物名称', name: 'Goods_Name',isAllowHide:true },
  4. { display: '种植面积(亩)', name: 'Areas' }],
  5. param: {},
  6. editor: {
  7. url: "",
  8. para: ["Goods_Name"]
  9. },
  10. ajaxURL: "/Pages/Hander/Highcharts.ashx"
  11. });
  12. });

扩展Jquery方法创建LigerUI Grid的更多相关文章

  1. jquery 扩展插件方法

    分析插件jquery.countdown.js (function($) { $.fn.countdown = function(options) { // default options var d ...

  2. 扩展JQuery和JS的方法

    //JS的扩展方法: 1 定义类静态方法扩展 2 定义类对象方法扩展            var aClass = function(){} //1 定义这个类的静态方法            aC ...

  3. 封装jQuery Validate扩展验证方法

    一.封装自定义验证方法-validate-methods.js /***************************************************************** j ...

  4. JQuery方法扩展

    第一种 extend <!-- extend 扩展jQuery,其实就是增加一个静态方法 --> 定义: $.extend({ sayHello:function(name) { aler ...

  5. jquery validate扩展验证方法

    /***************************************************************** jQuery Validate扩展验证方法 (linjq) *** ...

  6. [ligerUI] grid封装调用方法

    /** * 获取页面参数 */ function getPageSize(){ var xScroll, yScroll; if (window.innerHeight && wind ...

  7. jQuery Validate扩展验证方法 (zhangxiaobin)

    /***************************************************************** jQuery Validate扩展验证方法 (zhangxiaob ...

  8. 扩展ToolBarManager、ListView和Grid控件以实现气球式的ToolTip

    原文:扩展ToolBarManager.ListView和Grid控件以实现气球式的ToolTip infragistics是全球领先的UI工具和用户体验的专家,Infragistics开发了一系列的 ...

  9. 扩展jquery easyui datagrid编辑单元格

    扩展jquery easyui datagrid编辑单元格 1.随便聊聊 这段时间由于工作上的业务需求,对jquery easyui比较感兴趣,根据比较浅薄的js知识,对jquery easyui中的 ...

随机推荐

  1. Codeforces gym102058 J. Rising Sun-简单的计算几何+二分 (2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2))

    J. Rising Sun time limit per test 1.0 s memory limit per test 1024 MB input standard input output st ...

  2. 最全python面试题

    Python语言特性 1 Python的函数参数传递 看两个例子: a = 1 def fun(a): a = 2 fun(a) print a # 1 a = [] def fun(a): a.ap ...

  3. go chapter 2 - read file(yaml)

    func main() { data, err := ioutil.ReadFile("D:/test/widua.go") if err != nil { fmt.Println ...

  4. 【Bzoj3527】【Luogu3338】[Zjoi2014]力(FFT)

    题面 Bzoj Luogu 题解 先来颓柿子 $$ F_i=\sum_{j<i}\frac{q_iq_j}{(i-j)^2}-\sum_{j>i}\frac{q_iq_j}{(i-j)^2 ...

  5. 洛谷——P2299 Mzc和体委的争夺战

    P2299 Mzc和体委的争夺战 题目背景 mzc与djn第四弹. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁(做过前三弹的都知道).但如此之多的男家丁吸引来了我们的体委(矮胖小伙),他要来 ...

  6. EasyUI学习总结(六)——EasyUI布局(转载)

    本文转载自:http://www.cnblogs.com/xdp-gacl/p/4088198.html 一.EasyUI布局介绍 easyUI布局容器包括东.西.南.北.中五个区域,其中中心面板是必 ...

  7. 【BZOJ 4650】【UOJ #219】【NOI 2016】优秀的拆分

    http://www.lydsy.com/JudgeOnline/problem.php?id=4650 http://uoj.ac/problem/219 这里有非常好的题解qwq 接着道题复习一下 ...

  8. luogu P1440 求m区间内的最小值

    题目描述 一个含有n项的数列(n<=2000000),求出每一项前的m个数到它这个区间内的最小值.若前面的数不足m项则从第1个数开始,若前面没有数则输出0. 输入输出格式 输入格式: 第一行两个 ...

  9. 【BFS】bzoj1054 [HAOI2008]移动玩具

    暴搜吧,可以哈希一下,但是懒得写哈希了,所以慢得要死. Code: #include<cstdio> #include<queue> #include<set> # ...

  10. 【动态规划/递推】BZOJ1806[IOI2007]- Miners

    IOI历史上的著名水题,我这种蒟蒻都能写的东西. [思路] 用1.2.3分别代替三种食物,0表示当前矿井没有食物.f[i][a][b][c][d]当前第i个食物,矿1的食物顺序由上至下为a,b:矿2的 ...