扩展Jquery方法创建LigerUI Grid
- ///**
- //*封装jquery get请求ajax
- //*author:叶明龙
- //*time:2012-12-10
- //*/
- function getAjax(url, para, fn) {
- if (typeof fn == "function") {
- if (para == undefined) {
- para = {};
- }
- $.get(url, para, function (data) {
- var obj = eval("(" + data + ")");
- fn.call(this, obj);
- })
- }
- }
- /**
- *扩展Jquery方法创建LigerUI Grid
- *============================================
- *author:叶明龙
- *time:2014/06/21
- *
- *
- *============================================
- */
- ; (function ($) {
- $.fn.extend({
- createLigerGrid: function (opt) {
- var _t = $(this);
- var options = $.extend(true, {
- header: [],
- title: "",
- param: {},
- ajaxURL: "",
- ajaxMethod: "get",
- pageSize: 20,
- keyID: "",//主键
- editor: {
- url: "",
- para: [],
- width: 600,
- height: 600
- },
- success: function () { }
- }, opt);
- options.header.unshift({
- name: 'id', display: '操作', width: 100, isAllowHide: false,
- render: function (record, rowindex, value, column) {
- //this 这里指向grid
- //record 行数据
- //rowindex 行索引
- //value 当前的值,对应record[column.name]
- //column 列信息record[options.editor.para[0]]
- var _deleConfirm = "$.ligerDialog.confirm('确定删除?', function (yes) {";
- _deleConfirm += " if (yes) {";
- _deleConfirm += " getAjax('" + options.ajaxURL + "?type=delete&" + "id=" + record[options.editor.para[0]] + "',";
- _deleConfirm += "{";
- var _f = false;
- for (var pn in options.param) {
- if (_f)
- _deleConfirm += ",";
- _deleConfirm += "'" + pn + "':'" + options.param[pn] + "'";
- _f = true;
- }
- _deleConfirm += "}";
- _deleConfirm += ",function(data){";
- _deleConfirm += "if(data.success)$.ligerDialog.success('删除成功');else $.ligerDialog.error('删除失败');";
- _deleConfirm += "})";
- _deleConfirm += " }";
- _deleConfirm += " });";
- //onclick='eval(" + _deleConfirm + ");'
- return "<a href='javascript:;' onclick=\"" + _deleConfirm + "\">删除</a> <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>";
- }
- });
- if (options.ajaxURL == "") {
- $.ligerDialog.warn("未填写请求ajaxURL,无法响应服务器请求数据响应");
- return false;
- }
- var Grid = $(_t).ligerGrid({
- title: options.title,
- columns: options.header,
- pageSize: options.pageSize,
- method: options.ajaxMethod,
- url: options.ajaxURL,
- checkbox: true,
- toolbarShowInLeft: true,
- toolbar: {
- items: [{
- text: '添 加', click: function () {
- $.ligerDialog.open({ width: options.editor.width, height: options.editor.height, title: "添 加", url: options.editor.url + "?type=add" });
- }, icon: 'add'
- },
- {
- text: '删 除', click: function () {
- $.ligerDialog.confirm('确定删除?', function (yes) {
- if (yes) {
- var _Rows = Grid.getSelectedRows(), _keys = []
- for (var i = 0; i < _Rows.length; i++) {
- _keys.push(_Rows[i][options.editor.para[0]]);
- }
- getAjax(options.ajaxURL + "?type=delete&id=" + _keys.join(','), options.param, function (data) {
- if (data.success)
- $.ligerDialog.success('删除成功');
- else
- $.ligerDialog.error('删除失败');
- });
- }
- });
- }, icon: 'delete'
- }
- ]
- },
- root: "data",
- record: "total",
- width: '100%',
- height: '100%',
- heightDiff: -10,
- usePager: true,
- enabledSort: false,
- parms: options.param,
- pageSizeOptions: [5, 10, 15, 20],
- onCheckRow: function (checked, data, rowid, rowdata) {
- },
- onLoaded: function (grid) {
- grid.toggleLoading(false);
- if (options.success)
- options.success($(_t).data("request_data"), grid);
- },
- onSuccess: function (data, grid) {
- $(_t).data("request_data", data);
- },
- onError: function (XMLHttpRequest, textStatus, errorThrown) {
- $.ligerDialog.warn("数据加载错误");
- }
- });
- return Grid;
- }
- });
- })(jQuery);
页面调用示例
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title></title>
- <link rel="Stylesheet" type="text/css" href="/Content/css/Custom.css" />
- <link rel="stylesheet" type="text/css" href="/Content/js/LigerUI/skins/Aqua/css/ligerui-all.css" />
- <link rel="stylesheet" type="text/css" href="Content/js/LigerUI/skins/Gray/css/all.css" />
- <link rel="stylesheet" type="text/css" href="Content/js/LigerUI/skins/ligerui-icons.css" />
- <link href="/Content/css/default.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="/Content/js/jquery-1.7.2.min.js"></script>
- <script type="text/javascript" src="/Content/js/LigerUI/ligerui.all.js"></script>
- <script type="text/javascript" src="/Content/js/js2014.js"></script>
- <script src="/Content/js/jquery.cookie.js" type="text/javascript"></script>
- <script src="Content/js/JSON2.JS"></script>
- <script type="text/javascript" src="/Content/js/PUBLIC.JS"></script>
- <script type="text/javascript">
- $(document).ready(function () {
- $("#Grid").createLigerGrid({
- header: [{ display: '农作物名称', name: 'Goods_Name',isAllowHide:true },
- { display: '种植面积(亩)', name: 'Areas' }],
- param: {'flag':1},
- editor: {
- url: "",
- para: ["Goods_Name"]
- },
- ajaxURL: "/Pages/Hander/Highcharts.ashx"
- });
- });
- </script>
- </head>
- <body>
- <div id="Grid"></div>
- </body>
- </html>
- $(document).ready(function () {
- $("#Grid").createLigerGrid({
- header: [{ display: '农作物名称', name: 'Goods_Name',isAllowHide:true },
- { display: '种植面积(亩)', name: 'Areas' }],
- param: {},
- editor: {
- url: "",
- para: ["Goods_Name"]
- },
- ajaxURL: "/Pages/Hander/Highcharts.ashx"
- });
- });
扩展Jquery方法创建LigerUI Grid的更多相关文章
- jquery 扩展插件方法
分析插件jquery.countdown.js (function($) { $.fn.countdown = function(options) { // default options var d ...
- 扩展JQuery和JS的方法
//JS的扩展方法: 1 定义类静态方法扩展 2 定义类对象方法扩展 var aClass = function(){} //1 定义这个类的静态方法 aC ...
- 封装jQuery Validate扩展验证方法
一.封装自定义验证方法-validate-methods.js /***************************************************************** j ...
- JQuery方法扩展
第一种 extend <!-- extend 扩展jQuery,其实就是增加一个静态方法 --> 定义: $.extend({ sayHello:function(name) { aler ...
- jquery validate扩展验证方法
/***************************************************************** jQuery Validate扩展验证方法 (linjq) *** ...
- [ligerUI] grid封装调用方法
/** * 获取页面参数 */ function getPageSize(){ var xScroll, yScroll; if (window.innerHeight && wind ...
- jQuery Validate扩展验证方法 (zhangxiaobin)
/***************************************************************** jQuery Validate扩展验证方法 (zhangxiaob ...
- 扩展ToolBarManager、ListView和Grid控件以实现气球式的ToolTip
原文:扩展ToolBarManager.ListView和Grid控件以实现气球式的ToolTip infragistics是全球领先的UI工具和用户体验的专家,Infragistics开发了一系列的 ...
- 扩展jquery easyui datagrid编辑单元格
扩展jquery easyui datagrid编辑单元格 1.随便聊聊 这段时间由于工作上的业务需求,对jquery easyui比较感兴趣,根据比较浅薄的js知识,对jquery easyui中的 ...
随机推荐
- 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 ...
- 最全python面试题
Python语言特性 1 Python的函数参数传递 看两个例子: a = 1 def fun(a): a = 2 fun(a) print a # 1 a = [] def fun(a): a.ap ...
- go chapter 2 - read file(yaml)
func main() { data, err := ioutil.ReadFile("D:/test/widua.go") if err != nil { fmt.Println ...
- 【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 ...
- 洛谷——P2299 Mzc和体委的争夺战
P2299 Mzc和体委的争夺战 题目背景 mzc与djn第四弹. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁(做过前三弹的都知道).但如此之多的男家丁吸引来了我们的体委(矮胖小伙),他要来 ...
- EasyUI学习总结(六)——EasyUI布局(转载)
本文转载自:http://www.cnblogs.com/xdp-gacl/p/4088198.html 一.EasyUI布局介绍 easyUI布局容器包括东.西.南.北.中五个区域,其中中心面板是必 ...
- 【BZOJ 4650】【UOJ #219】【NOI 2016】优秀的拆分
http://www.lydsy.com/JudgeOnline/problem.php?id=4650 http://uoj.ac/problem/219 这里有非常好的题解qwq 接着道题复习一下 ...
- luogu P1440 求m区间内的最小值
题目描述 一个含有n项的数列(n<=2000000),求出每一项前的m个数到它这个区间内的最小值.若前面的数不足m项则从第1个数开始,若前面没有数则输出0. 输入输出格式 输入格式: 第一行两个 ...
- 【BFS】bzoj1054 [HAOI2008]移动玩具
暴搜吧,可以哈希一下,但是懒得写哈希了,所以慢得要死. Code: #include<cstdio> #include<queue> #include<set> # ...
- 【动态规划/递推】BZOJ1806[IOI2007]- Miners
IOI历史上的著名水题,我这种蒟蒻都能写的东西. [思路] 用1.2.3分别代替三种食物,0表示当前矿井没有食物.f[i][a][b][c][d]当前第i个食物,矿1的食物顺序由上至下为a,b:矿2的 ...