Lisong's Blog


四月 6th, 2010

FlexiGrid IE8修复和扩展,适应新版jQuery

Learning, by 木公.

刚刚结束了一个内部WEB的开发,在这期间用到了一个jQuery表格插件:FlexiGrid,目前的官方版本为1.0beta3。此最新版在IE8下style有错位问题,而且不支持1.3+以上的新版jQuery,所以我在使用时不得不做了修复,顺便为它增加了一些新的功能,比如右键菜单。

参数说明:

        p = $.extend({
            height: 200,  //表格高度,默认200
            width: 'auto', //表格宽度,默认自动
            striped: true, //是否显示斑纹效果,默认是奇偶交互的形式
            novstripe: false,
            minwidth: 30, //列最小宽度
            minheight: 80, //列最大宽度
            resizable: true, //是否可以伸缩大小
            url: false, //ajax地址
            method: 'POST', // 数据发送方式(即为$.ajax({method:'POST'}))
            dataType: 'xml', // 加载的数据格式(xml、json)
            errormsg: 'Connection Error', //出错时的提示信息
            usepager: false, //是否可以分页
            nowrap: true, // 是否不允许换行
            page: 1, // 当前第几页
            total: 1, // 总共多少页
            useRp: true, // 是否可以动态设置每页显示的结果数
            rp: 15, // 每页结果数
            rpOptions: [10, 15, 20, 25, 40], //设置可以选择的每页结果数
            title: false, //是否显示title
            pagestat: 'Displaying {from} to {to} of {total} items', //显示当前页和总页面的样式
            procmsg: 'Processing, please wait ...', // 数据加载是的提示信息
            query: '', //搜索查询条件,在我改过之后,似乎已失效,我也没用到过
            qtype: '', //同上
            nomsg: 'No items', //没有查询到记录时显示
            minColToggle: 1, //允许显示的最小列数
            showToggleBtn: true, //是否允许显示隐藏列
            hideOnSubmit: true, //是否在回调时显示遮盖
            autoload: true, //自动加载
            blockOpacity: 0.5, //透明度设置
            onToggleCol: false, //当在行之间转换时,可在此方法中重写默认实现
            onChangeSort: false, //当改变排序时,可在此方法中重写默认实现
            onSuccess: false, //每次加载成功后执行的函数
            onSubmit: false, // 调用自定义的计算函数,我从来没用到过
            canSelect: false, //是否允许选中行
            quichtml: '', // 替换了原版本的快速搜索栏html
            rowhandler: false, // 给每行绑定右击事件
            rowClick: false //单击行时的事件函数
        }, p);

应用实例:

function getFileName(file) {
            var temp = file.split("/");
            return temp[temp.length - 1];
        }
function formatLink(tdDiv, pid) {
            var value = $(tdDiv).text();
            if (value.length > 1) {
                $(tdDiv).html("<a href='http://*****/" + value + "' target='_blank'>" + getFileNmae(value) + "</a>");
            } else {
                $(tdDiv).html("<font color='lightgrey'>No ppt file</font>");
            }
        }
function loadData(row) {
            var id = parseInt(row.id.replace('row', ''));
            $('#result').attr('disabled', 'disabled');
            $.ajax({
                url: "ImportFromOld.aspx?action=loadData",
                cache: false,
                type: "POST",
                data: "ID=" + id,
                success: function(json) {
                    var data = eval('(' + json + ')');
                    $('#ProjectID').val(id);
                    $('#ProjectName').val(data.description);
                    $('#Workcell').val(data.workcell);
                    $('#Department').val(data.department);
                    $('#Leader').val(data.pic);
                    $('#StartDate').val(data.start);
                    $('#DueDate').val(data.due);
                    $('#ProjectStatus').val(data.status);
                    $('#file').val(data.link);
                    $('#Duration').val(dateDiff('D', data.start, data.due));
                    $('#result').removeAttr('disabled');
                }
            });
        }
function contextmenu(row) {
            var menu = { width: 150, items: [
                     { text: "Modify", icon: "images/icons/edit.png", alias: "contextmenu-edit", action: contextMenuItem_click },
                     { text: "Validate", icon: "images/icons/view.png", alias: "contextmenu-validate", action: contextMenuItem_click },
                     { text: "Delete", icon: "images/icons/rowdelete.png", alias: "contextmenu-delete", action: contextMenuItem_click },
                     { text: "Refresh", icon: "images/icons/table_refresh.png", alias: "contextmenu-reflash", action: contextMenuItem_click }
                ]
            };
            function contextMenuItem_click(target) {
                var id = $(target).attr("id").substr(3);
                var cmd = this.data.alias;
                var ch = $.browser.msie ? target.ch : target.getAttribute("ch");
                if (cmd == "contextmenu-edit") {
                    window.open("Admin/?method=modify&id=" + id);
                }
                else if (cmd == "contextmenu-validate") {
                    window.open("Admin/?method=validate&id=" + id);
                }
                else if (cmd == "contextmenu-delete") {
                    deleteid = id;
                    $('#delete-info').dialog('open');
                }
                else {
                    $("#result").flexReload();
                }
            }
            $(row).contextmenu(menu);
        }
 
     $(document).ready(function() {
            var flexioption = {
                url: 'importfromold.aspx?action=read',
                dataType: 'json',
                method: 'POST',
                colModel: [
				    { display: 'Project Name', name: 'Description', width: 290, sortable: true, align: 'left' },
				    { display: 'Workcell', name: 'Workcell', width: 100, sortable: true, align: 'center' },
				    { display: 'Department', name: 'Department', width: 100, sortable: false, align: 'center' },
				    { display: 'Project Leader', name: 'PIC', width: 150, sortable: true, align: 'center' },
				    { display: 'Start date', name: 'Start', width: 120, sortable: true, align: 'center' },
				    { display: 'Due date', name: 'Due', width: 120, sortable: true, align: 'center' },
				    { display: 'Project status', name: 'Status', width: 130, sortable: true, align: 'center' },
				    { display: 'Powerpoint', name: 'Link', width: 150, sortable: false, align: 'center', process: formatLink }
				],
                sortname: 'Description',
                sortorder: 'asc',
                usepager: false,
                showTableToggleBtn: true,
                height: document.documentElement.clientHeight / 2 - 100,
                hideOnSubmit: true,
                nomsg: 'No records of your search.',
                striped: true,
                canSelect: true,
                singleSelect: true,
                rowhandler: contextmenu,
                rowClick: loadData
            };
            $('#result').flexigrid(flexioption);
});

Back Top

回复自“FlexiGrid IE8修复和扩展,适应新版jQuery”

评论 (9) 引用 (0) 发表评论 引用地址
  1. 雁过留名,博主厉害

  2. 杯过也留名 完全看不懂 ⊙﹏⊙b~~

    微笑D咖啡杯 CHINA Google Chrome Windows at 四月 12, 2010 7:24 下午
  3. @微笑D咖啡杯 术业有专攻(^_^)∠※

  4. 由于我的这个是专门针对自己项目做的修改,在别的项目上可能会有部分不适应,推荐http://www.cnblogs.com/xuanye/archive/2009/11/04/xuanye_jquery_flexigrid.html 这篇文章

  5. 你好,能否说明一下修改了什么地方,怎么改的,在下愚钝,看了源码,没有看出来修改了哪些地方?

  6. I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading.

  7. 朋友,我來咯。。在來踩踩。呵呵。

  8. I would like to propose not to hold back until you get enough amount of money to buy all you need! You should take the home loans or just term loan and feel yourself comfortable

  9. Photoshop is an amazing tool for altering reality, but it's only really great when you're aware of its effects. There are several tools existing to help people detect Photoshopped images. Of them site Photoshopped Image Killer offers the best result. Unlike other forensic analysis tool, pskiller.com analyzes image integrity in the content level, which is more accurate and reliable.

  1. 没有任何引用。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


无觅相关文章插件,快速提升流量