首页 > PHP资讯 > HTML5培训技术 > jQueryEasyUiDataGrid增删改查

jQueryEasyUiDataGrid增删改查

HTML5培训技术
function xwUtil() {
    this.page_template = "/template/NO_LOGIN_transfer.ashx";
    this.before_tip = "正在加载";
    this.save_price = function() {
        var that = this;
        var swichParam = "save_price";
        var obj = arguments[0];
        $.ajax({
            type: "POST",
            url: that.page_template,
            data: "swichParam={0}&cpbjrq={1}&cp={2}&gg={3}&jldw={4}&zgj={5}&zdj={6}&pjj={7}&zf={8}&dq={9}&sjly={10}&zt={11}&bjr={12}&price_log_id={13}"
                .replace("{0}", swichParam).replace("{1}", obj.cpbjrq)
                .replace("{2}", obj.cp).replace("{3}", obj.gg)
                .replace("{4}", obj.jldw).replace("{5}", obj.zgj)
                .replace("{6}", obj.zdj).replace("{7}", obj.pjj)
                .replace("{8}", obj.zf).replace("{9}", obj.dq)
                .replace("{10}", obj.dq).replace("{10}", obj.sjly)
                .replace("{11}", obj.zt).replace("{12}", obj.bjr)
                .replace("{13}", obj.price_log_id),
            success: function(msg) {
                if (msg != "true") {
                    alert(msg);
                }
            },
            beforeSend: function() {
                //                $(divid).html(that.before_tip);
            },
            error: function(msg) {
                //                var url1 = that.page_template + "?swichParam={0}".replace("{0}", that.xls);
                //                $(divid).html("提取数据错误!" + url1);
            }
        });
    }
    this.upload_price = function() {
        var that = this;
        var swichParam = "upload_price";
        var obj = arguments[0];
        $.ajax({
            type: "POST",
            url: that.page_template,
            data: "swichParam={0}&cpbjrq={1}&cp={2}&gg={3}&jldw={4}&zgj={5}&zdj={6}&pjj={7}&zf={8}&dq={9}&sjly={10}&zt={11}&bjr={12}&price_log_id={13}&xh={14}&action={15}"
                .replace("{0}", swichParam).replace("{1}", obj.cpbjrq)
                .replace("{2}", obj.cp).replace("{3}", obj.gg)
                .replace("{4}", obj.jldw).replace("{5}", obj.zgj)
                .replace("{6}", obj.zdj).replace("{7}", obj.pjj)
                .replace("{8}", obj.zf).replace("{9}", obj.dq)
                .replace("{10}", obj.dq).replace("{10}", obj.sjly)
                .replace("{11}", obj.zt).replace("{12}", obj.bjr)
                .replace("{13}", obj.price_log_id).replace("{14}", obj.xh)
                .replace("{15}", obj.action),
            success: function(msg) {
                if (msg != "true") {
                    alert(msg);
                }
            },
            beforeSend: function() {
                //                $(divid).html(that.before_tip);
            },
            error: function(msg) {
                //                var url1 = that.page_template + "?swichParam={0}".replace("{0}", that.xls);
                //                $(divid).html("提取数据错误!" + url1);
            }
        });
    }
    //无参数template
    this.update_no_params_xls = function() {
        var that = this;
        var swichParam = arguments[0].swichParam;
        $.ajax({
            type: "POST",
            url: that.page_template,
            data: "swichParam={0}".replace("{0}", swichParam),
            success: function(msg) {
            },
            beforeSend: function() {
                //                $(divid).html(that.before_tip);
            },
            error: function(msg) {
                var url1 = that.page_template + "?swichParam={0}".replace("{0}", that.xls);
                //                $(divid).html("提取数据错误!" + url1);
            }
        });
    }
    this.getJson = function() {
        var that = this;
        var swichParam = arguments[0].swichParam;
        var isBianji = (arguments[0].price_log_id != "");
        $.ajax({
            type: "POST",
            dataType: "json",
            url: that.page_template,
            data: "swichParam={0}&price_log_id={1}"
            .replace("{0}", swichParam)
            .replace("{1}", arguments[0].price_log_id),
            success: function(msg) {
                //$('#tt').datagrid("loadData", msg);
                //alert(msg);
                //document.write(msg);
                //msg = { "Table": [{ "id": "23", "productId": "2", "bjrq": "2010-1-4 0:00:00", "gg": "", "zdjg": "70000", "zgjg": "71000", "pjjg": "", "jldw": "人民币元/吨", "zf": "1", "dq": "大余", "xxly": "中国铁合金在线", "addTime": "2011-7-1 17:31:34", "Szz": "", "zt": "", "ext1": ""}] };
                //msg = "'" + msg + "'";
                //alert(msg);
                //msg = eval(msg);
                for (var i in msg) {
                    for (var p = 0; p < msg[i].length; p++) {
                        var obj = msg[i][p];
                        $('#tt').datagrid('appendRow', {
                            xh: isBianji ? obj.id : $('#tt').datagrid('getRows').length + 1,
                            //序号
                            //itemid: 0,
                            //产品报价日期
                            productid: obj.bjrq,
                            //产品
                            listprice: obj.ext1,
                            //规格
                            unitcost: obj.gg,
                            //计量单位
                            attr1: obj.jldw,
                            //最高价
                            status: obj.zgjg,
                            //最低价
                            zdj: obj.zdjg,
                            //平均价
                            pjj: obj.pjjg,
                            //走势
                            zf: obj.zf,
                            //地区
                            dq: obj.dq,
                            //数据来源
                            sjly: obj.xxly
                        });
                        //alert(msg[i][p].bjrq);
                    }
                }
            },
            beforeSend: function() {
                //$(divid).html(that.before_tip);
            },
            error: function(msg) {
                //var url1 = that.page_template + "?swichParam={0}".replace("{0}", that.xls);
                //$(divid).html("提取数据错误!" + url1);
            }
        });
    }
}
var xw = new xwUtil();
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="T_jgAdd2.aspx.cs" Inherits="ImisPortalXiaWuManager.Modules.T_jgAdd2" %>

    
    
    <script type="text/javascript" src="http://www.cnblogs.com/js/jquery-easyui-1.2.3/jquery-1.4.4.min.js">《script》
    <script type="text/javascript" src="http://www.cnblogs.com/js/jquery-easyui-1.2.3/jquery.easyui.min.js">《script》
    <script src="http://www.cnblogs.com/js/Util/xwUtil.js">《script》


    
        添加T_jg

    
        
            
                
                
                
                
                
            
        

                    新增产品报价日期:
                

                    
                

                    编辑责任人:
                

                    
                        
                    
                

                                            type="button" value="返回" />
                

                    idfield="xh" url="datagrid_data2.json">
            
                
                    <%-- 
                    --%>
                    
                        序号
                    
                    
                        产品报价日期
                    
                    <%--                    editor="{type:'combobox',options:{valueField:'productid',textField:'name',data:products,required:true}}">
                        产品报价日期
                    --%>
                    
                        产品
                    
                    <%--
                        产品
                    --%>
                    
                        规格
                    
                    <%-- 
                        规格
                    --%>
                    
                        计量单位
                    
                    <%----%>
                    
                        最高价
                    
                    
                        最低价
                    
                    
                        平均价
                    
                    
                        涨幅
                    
                    
                        地区
                    
                    
                        数据来源
                    
                
            
        
    

    《script》
        function getAction()
        {
            if("<%=PriceLogId %>"=="" ||"<%=PriceLogId %>"=="0" )
            {
                return "upload_save";
            }else{
                return "upload_update";
            }
        }
        var products = [
                    { productid: '1', name: '上涨' },
                    { productid: '0', name: '下降' }
                ];
        function productFormatter(value) {
            for (var i = 0; i < products.length; i++) {
                if (products[i].productid == value) return products[i].name;
            }
            return value;
        }
        $(function() {
            var lastIndex;
            xw.getJson({ "swichParam": "get_prev_datetime_data", "price_log_id": "<%=PriceLogId %>" });
            $('#tt').datagrid({
                toolbar: [{
                    text: '新增产品名细',
                    iconCls: 'icon-add',
                    handler: function() {
                        $('#tt').datagrid('endEdit', lastIndex);
                        $('#tt').datagrid('appendRow', {
                            xh: $('#tt').datagrid('getRows').length + 1,
                            //序号
                            //                            itemid: 0,
                            //产品报价日期
                            productid: '<%=DtNow %>',
                            //产品
                            listprice: '',
                            //规格
                            unitprice: '',
                            //计量单位
                            attr1: '',
                            //最高价
                            status: '',
                            //最低价
                            zdj: '',
                            //平均价
                            pjj: '',
                            //走势
                            zf: '0',
                            //地区
                            dq: '',
                            //数据来源
                            sjly: ''
                        });
                        var lastIndex = $('#tt').datagrid('getRows').length - 1;
                        $('#tt').datagrid('selectRow', lastIndex);
                        $('#tt').datagrid('beginEdit', lastIndex);
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function() {
                        var row = $('#tt').datagrid('getSelected');
                        if (row) {
                            var index = $('#tt').datagrid('getRowIndex', row);
                            $('#tt').datagrid('deleteRow', index);
                        }
                    }
                }, '-', {
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function() {
//                        xw.update_no_params_xls({ "swichParam": "update_price_log" });
                        //var data = $('#tt').datagrid('acceptChanges').datagrid('getData');
                        var data = $('#tt').datagrid('acceptChanges').datagrid('getData');
                        for (var i = 0; i < data.rows.length; i++) {
                            var cpbjrq = data.rows[i].productid;
                            var cp = data.rows[i].listprice;
                            var gg = data.rows[i].unitcost;
                            var jldw = data.rows[i].attr1;
                            var zgj = data.rows[i].status;
                            var zdj = data.rows[i].zdj;
                            var pjj = data.rows[i].pjj;
                            var zf = data.rows[i].zf;
                            var dq = data.rows[i].dq;
                            var sjly = data.rows[i].sjly;
                            xw.save_price({ "cpbjrq": cpbjrq,
                                "cp": cp,
                                "gg": gg,
                                "jldw": jldw,
                                "zgj": zgj,
                                "zdj": zdj,
                                "pjj": pjj,
                                "zf": zf,
                                "dq": dq,
                                "sjly": sjly,
                                "zt": 0,
                                "bjr": document.getElementById('<%=DropDownList1.ClientID %>').value,
                                "price_log_id": "<%=vs_PriceLogId %>"
                            });
                        }
                        alert('数据保存成功!');
                    }
                }, '-', {
                    text: '撤销',
                    iconCls: 'icon-undo',
                    handler: function() {
                        $('#tt').datagrid('rejectChanges');
                    }
                }, '-', {
                    text: '上传',
                    //iconCls: 'icon-undo',
                    handler: function() {
                        //更新Price Log
//                        xw.update_no_params_xls({ "swichParam": "update_price_log" });
                        var data = $('#tt').datagrid('acceptChanges').datagrid('getData');
                        //更新Price表
                        for (var i = 0; i < data.rows.length; i++) {
                            var cpbjrq = data.rows[i].productid;
                            var cp = data.rows[i].listprice;
                            var gg = data.rows[i].unitcost;
                            var jldw = data.rows[i].attr1;
                            var zgj = data.rows[i].status;
                            var zdj = data.rows[i].zdj;
                            var pjj = data.rows[i].pjj;
                            var zf = data.rows[i].zf;
                            var dq = data.rows[i].dq;
                            var sjly = data.rows[i].sjly;
                            xw.upload_price({ "cpbjrq": cpbjrq,
                                "cp": cp,
                                "gg": gg,
                                "jldw": jldw,
                                "zgj": zgj,
                                "zdj": zdj,
                                "pjj": pjj,
                                "zf": zf,
                                "dq": dq,
                                "sjly": sjly,
                                "zt": 1,
                                "bjr": document.getElementById('<%=DropDownList1.ClientID %>').value,
                                "price_log_id": "<%=vs_PriceLogId %>",
                                "xh": data.rows[i].xh,
                                "action": getAction()
                            });
                        }
                        alert('数据上传成功!');
                    }
                }
                /*, '-', {
                text: 'getChanges',
                iconCls: 'icon-search',
                handler: function() {
                var rows = $('#tt').datagrid('getChanges');
                alert('changed rows: ' + rows.length + ' lines');
                }
                }*/
                ],
                onBeforeLoad: function() {
                    $(this).datagrid('rejectChanges');
                },
                onClickRow: function(rowIndex) {
                    if (lastIndex != rowIndex) {
                        $('#tt').datagrid('endEdit', lastIndex);
                        $('#tt').datagrid('beginEdit', rowIndex);
                    }
                    lastIndex = rowIndex;
                }
            });
        });
    《script》

上一篇:jQuery中如何操作radio、checkbox、select
下一篇:jQueryajaxreturn没有返回值的解决方法

HTML5培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持2不支持0