2

サーバーリクエストであるユーザーデータなしでjqGridサマリーフッターにデータを入力することに関連して、このWebサイトで尋ねられたすべての質問に答えました。そして、jqGrid wiki リソースと答えが見つかりません。これは可能ですか?

私は jqGrid を管理ポータルの一部として多くの典型的な方法で使用していますが、jqGrid のルック アンド フィールを、フォームを介して行を追加するユーザー インタラクションのための種類の空の UI コンテナーとして開始する特定の用途があります。 Submit に投稿するのではなく (以下の Oleg の優れたスクリプトのおかげです)、単純に行を追加し、新しく追加された行の値で概要フッターを更新します。colModel に 'summarytype:"sum"'、"grouping:true"、footerrow: true、userDataOnFooter: true、altRows: true、グリッド オプションにありますが、ローカル データ文字列の userdata によって提供される初期値は別として、概要フッターの値は変更されません。誰もこの話題に触れたくないようです。jqGridの主な性質がそれだからですか?データベース主導の機能ですか。私はデータベース駆動型のスタンスで jqGrid の約 15 のインスタンスを使用しますが (その多くは現在実稼働サービスにあります)、一貫性のために使用する必要があります (すべての UI は jqTabs 内にあります)。最初はサーバー要求のないクライアント側 UI として使用します。 (すべては後で db に保存されます) しかし、要約フッターをクライアントのみでプログラムによって操作しようとして、髪を引っ張っています。新しい行が追加されたときにサマリーフッターの値を更新する方法を提案できますか? s は jqTabs 内にあります) 最初はサーバー要求のないクライアント側の UI として (すべては後で db に保存されます)、クライアントのみでプログラムによって要約フッターを操作しようとしています。新しい行が追加されたときにサマリーフッターの値を更新する方法を提案できますか? s は jqTabs 内にあります) 最初はサーバー要求のないクライアント側の UI として (すべては後で db に保存されます)、クライアントのみでプログラムによって要約フッターを操作しようとしています。新しい行が追加されたときにサマリーフッターの値を更新する方法を提案できますか?

提供されるコードはやや長く、主にサーバーに投稿せずにモーダル フォームから行を追加するユーザー Oleg のソリューションに基づいています。ローカル配列データを JSON 文字列に変更したのは、xml に慣れているため、表記法をよりよく理解するためだけです。jsonstring は、ユーザーが編集する 1 つの既定の行でグリッドを初期化します。グリッドがレンダリングされないため、jsonReader は省略しました。

一言で言えば、私がやりたいことは、新しい行がグリッドに追加されたとき (この時点ではサーバーへの投稿は発生していません)、編集または削除されたときにサマリー フッターを更新することです。特定の値のセットが達成されると、行データを db に保存するようにボタンが表示されます。

var lastSel, mydata = { "total": 1, "page": 1, "records": 1, "rows": [{ "id": acmid, "cell": ["0.00", "0.00", "0.00", "0.00"]}], "userdata":{ "mf": 0.00, "af":0.00,"pf":0.00,"cf":0.00 }}

grid = $("#ta_form_d"),
    onclickSubmitLocal = function (options, postdata) {

        var grid_p = grid[0].p,
            idname = grid_p.prmNames.id,
            grid_id = grid[0].id,
            id_in_postdata = grid_id + "_id",
            rowid = postdata[id_in_postdata],
            addMode = rowid === "_empty",
            oldValueOfSortColumn;

        // postdata has row id property with another name. we fix it:
        if (addMode) {
            // generate new id
            var new_id = grid_p.records + 1;
            while ($("#" + new_id).length !== 0) {
                new_id++;
            }
            postdata[idname] = String(new_id);
            //alert(postdata[idname]);
        } else if (typeof (postdata[idname]) === "undefined") {
            // set id property only if the property not exist
            postdata[idname] = rowid;
        }

        delete postdata[id_in_postdata];

        // prepare postdata for tree grid
        if (grid_p.treeGrid === true) {
            if (addMode) {
                var tr_par_id = grid_p.treeGridModel === 'adjacency' ? grid_p.treeReader.parent_id_field : 'parent_id';
                postdata[tr_par_id] = grid_p.selrow;
            }

            $.each(grid_p.treeReader, function (i) {
                if (postdata.hasOwnProperty(this)) {
                    delete postdata[this];
                }
            });
        }

        // decode data if there encoded with autoencode
        if (grid_p.autoencode) {
            $.each(postdata, function (n, v) {
                postdata[n] = $.jgrid.htmlDecode(v); // TODO: some columns could be skipped
            });
        }

        // save old value from the sorted column
        oldValueOfSortColumn = grid_p.sortname === "" ? undefined : grid.jqGrid('getCell', rowid, grid_p.sortname);
        //alert(oldValueOfSortColumn);
        // save the data in the grid
        if (grid_p.treeGrid === true) {
            if (addMode) {
                grid.jqGrid("addChildNode", rowid, grid_p.selrow, postdata);
            } else {
                grid.jqGrid("setTreeRow", rowid, postdata);
            }
        } else {

           if (addMode) {
                grid.jqGrid("addRowData", rowid, postdata, options.addedrow);


            } else {
                grid.jqGrid("setRowData", rowid, postdata);
            }
        }

        if ((addMode && options.closeAfterAdd) || (!addMode && options.closeAfterEdit)) {
            // close the edit/add dialog
            $.jgrid.hideModal("#editmod" + grid_id,
                              { gb: "#gbox_" + grid_id, jqm: options.jqModal, onClose: options.onClose });
        }

        if (postdata[grid_p.sortname] !== oldValueOfSortColumn) {
            // if the data are changed in the column by which are currently sorted
            // we need resort the grid
            setTimeout(function () {
                grid.trigger("reloadGrid", [{ current: true}]);
            }, 100);
        }

        // !!! the most important step: skip ajax request to the server
        this.processing = true;
        return {};



    },

    editSettings = {
        //recreateForm:true,
        jqModal: false,
        reloadAfterSubmit: false,
        closeOnEscape: true,
        savekey: [true, 13],
        closeAfterEdit: true,
        onclickSubmit: onclickSubmitLocal
    },

    addSettings = {
        //recreateForm:true,
        jqModal: false,
        reloadAfterSubmit: false,
        savekey: [true, 13],
        closeOnEscape: true,
        closeAfterAdd: true,
        onclickSubmit: onclickSubmitLocal
    },

    delSettings = {
        // because I use "local" data I don't want to send the changes to the server
        // so I use "processing:true" setting and delete the row manually in onclickSubmit
        onclickSubmit: function (options, rowid) {
            var grid_id = grid[0].id,
                grid_p = grid[0].p,
                newPage = grid[0].p.page;

            // delete the row
            grid.delRowData(rowid);
            $.jgrid.hideModal("#delmod" + grid_id,
                              { gb: "#gbox_" + grid_id, jqm: options.jqModal, onClose: options.onClose });

            if (grid_p.lastpage > 1) {// on the multipage grid reload the grid
                if (grid_p.reccount === 0 && newPage === grid_p.lastpage) {
                    // if after deliting there are no rows on the current page
                    // which is the last page of the grid
                    newPage--; // go to the previous page
                }
                // reload grid to make the row from the next page visable.
                grid.trigger("reloadGrid", [{ page: newPage}]);
            }

            return true;
        },
        processing: true
    };         //,
    /*initDateEdit = function (elem) {
        setTimeout(function () {
            $(elem).datepicker({
                dateFormat: 'dd-M-yy',
                autoSize: true,
                showOn: 'button', // it dosn't work in searching dialog
                changeYear: true,
                changeMonth: true,
                showButtonPanel: true,
                showWeek: true
            });
            //$(elem).focus();
        }, 100);
    },
    initDateSearch = function (elem) {
        setTimeout(function () {
            $(elem).datepicker({
                dateFormat: 'dd-M-yy',
                autoSize: true,
                //showOn: 'button', // it dosn't work in searching dialog
                changeYear: true,
                changeMonth: true,
                showButtonPanel: true,
                showWeek: true
            });
            //$(elem).focus();
        }, 100);
    };*/

    //jQuery("#ta_form_d").jqGrid({
    grid.jqGrid({
        // url:'/admin/tg_cma/ta_allocations.asp?acmid=' + acmid + '&mid=' + merchantid + '&approval_code=' + approval_code,
        //datatype: "local",
        //data: mydata,
        datatype: 'jsonstring',
        datastr: mydata,

        colNames: ['ID', 'Monthly Fees', 'ATM Fees', 'POS Fees', 'Card to Card Fees'],
        colModel: [
        { name: 'id', index: 'id', width: 90, align: "center", editable: true, editoptions: { size: 25 }, formoptions: { rowpos: 1, colpos: 1, label: "EzyAccount ID", elmprefix: "(*) " }, editrules: { required: true} },
        { name: 'mf', index: 'mf', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 2, colpos: 1, label: "Monthly Fee", elmprefix: "(*) " }, editrules: { required: true} },
        { name: 'af', index: 'af', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 3, colpos: 1, label: "ATM Fee", elmprefix: "(*) " }, editrules: { required: true} },
        { name: 'pf', index: 'pf', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 4, colpos: 1, label: "POS Fee", elmprefix: "(*) " }, editrules: { required: true} },
        { name: 'cf', index: 'cf', width: 130, align: "right", formatter: 'number', editable: true, summaryType: 'sum', editoptions: { size: 25 }, formoptions: { rowpos: 5, colpos: 1, label: "Card to Card Fee", elmprefix: "(*) " }, editrules: { required: true} }
    ],
        rowNum: 5,
        rowList: [5, 10, 20],
        pager: '#pta_form_d',
        toolbar: [true, "top"],
        width: 500,
        height: 100,
        editurl: 'clientArray',
        sortname: 'id',
        viewrecords: true,
        sortorder: "asc",
        multiselect: false,
        cellEdit: false,
        caption: "Allocations",
        grouping: true,
        /*groupingView: { 
            groupField: ['id', 'mf', 'af', 'pf', 'cf'],
            groupColumnShow: [true],
            groupText: ['<b>{0}</b>'],
            groupCollapse: false,
            groupOrder: ['asc'],
            groupSummary: [true],
            groupDataSorted: true 
        },*/
        footerrow: true,
        userDataOnFooter: true,
        altRows: true,
        ondblClickRow: function (rowid, ri, ci) {
            var p = grid[0].p;
            if (p.selrow !== rowid) {
                // prevent the row from be unselected on double-click
                // the implementation is for "multiselect:false" which we use,
                // but one can easy modify the code for "multiselect:true"
                grid.jqGrid('setSelection', rowid);
            }
            grid.jqGrid('editGridRow', rowid, editSettings);
        },
        onSelectRow: function (id) {
            if (id && id !== lastSel) {
                // cancel editing of the previous selected row if it was in editing state.
                // jqGrid hold intern savedRow array inside of jqGrid object,
                // so it is safe to call restoreRow method with any id parameter
                // if jqGrid not in editing state
                if (typeof lastSel !== "undefined") {
                    grid.jqGrid('restoreRow', lastSel);
                }
                lastSel = id;
            }
        },
        afterEditCell: function (rowid, cellname, value, iRow, iCol) {
            alert(iCol);
        },
        gridComplete: function () {

        },
        loadComplete: function (data) {


        }

    })
.jqGrid('navGrid', '#pta_form_d', {}, editSettings, addSettings, delSettings,
          { multipleSearch: true, overlay: false,
              onClose: function (form) {
                  // if we close the search dialog during the datapicker are opened
                  // the datepicker will stay opened. To fix this we have to hide
                  // the div used by datepicker
                  //$("div#ui-datepicker-div.ui-datepicker").hide();
              }
          });

$("#t_ta_form_d").append("<input type='button' class='add' value='Add New Allocation' style='height:20px; color:green; font-size:11px;' />");
$("input.add", "#t_ta_form_d").click(function () {
    jQuery("#ta_form_d").jqGrid('editGridRow', "new", {
        //recreateForm:true,
        jqModal: false,
        reloadAfterSubmit: false,
        savekey: [true, 13],
        closeOnEscape: true,
        closeAfterAdd: true,
        onclickSubmit: onclickSubmitLocal


    })
})
4

1 に答える 1

9

「ローカル」データ型の場合、footerDataメソッドを使用してフッターのデータを設定 (または取得) できます。さらに、メソッドgetColを使用して、列内の要素の合計を計算できます。

詳細については、回答をご覧ください。それがあなたの問題を解決することを願っています。

于 2011-04-12T07:37:40.433 に答える