0

以下は、グリッドの読み込み、ページング、および並べ替えで正常に機能している私の JQGrid コードです。

ここで、編集および削除機能を追加する必要があります。

navbar で「編集」および「削除」オプションを有効にするために Google で見つけましたが、次のようにしたい ---- ユーザーが「a href」リンクをクリックすると、rowID とともに javascritp 関数を呼び出す必要があります。どうすればハイパーリンクを追加でき、クリックするとfunctinoを呼び出すことができますか?

        $('#CategoriesGrdList').jqGrid({
        ajaxGridOptions: {
            error: function () {
                $('#CategoriesGrdList')[0].grid.hDiv.loading = false;
                alert('An error has occurred.');
            }
        },
        url: '@Url.Action("GetAllCategoriesList", "Categories")/' + 0,
        gridview: true,
        autoencode: true,
        //public JsonResult GetEnrolls(int adClassSchedID,DateTime attendanceDate,int adProgramID,int syCampusID)
        postData: { categoryId: 1 },
        //postData: { categoryId: rowID, attendanceDate: $('#AttendanceDate').val(), adProgramID: $('#adProgramID').val(), syCampusID: $('#syCampusID').val() },
        datatype: 'json',
        jsonReader: { root: 'List', page: 'Page', total: 'TotalPages', records: 'TotalCount', repeatitems: false, id: 'Id' },
        mtype: 'GET',
        colNames: ['Id', 'Code', 'Description', 'IsActive'],
        colModel: [
              { name: 'Id', index: 'Id', hidden: true },
            { name: 'Code', index: 'Code', width: 170 },
            { name: 'Description', index: 'Description', width: 170 },
        { name: 'IsActive', index: 'IsActive', width: 170 }
        ],
        pager: $('#CategoriesGrdPager'),
        sortname: 'Code',
        rowNum: 40,
        rowList: [3, 3, 3],
        width: '525',
        height: '100%',
        viewrecords: true,

        beforeSelectRow: function (rowid, e) {
            return false;

        },
        sortorder: 'desc'
    }).navGrid('#CategoriesGrdPager', { edit: false, add: false, del: false, search: false, refresh: false });
});

ノート:

以下のコメントの1つからの提案として、列の下に追加:

                 {
                 name: 'act', index: 'act', width: 55, align: 'center', sortable: false,    formatter: 'actions',
                 formatoptions: {
                     keys: true, // we want use [Enter] key to save the row and [Esc] to cancel   editing.
                     onEdit: function (rowid) {
                         alert("in onEdit: rowid=" + rowid + "\nWe don't need return anything");
                     },
                     onSuccess: function (jqXHR) {
                         // the function will be used as "succesfunc" parameter of editRow function
                         // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow)
                         alert("in onSuccess used only for remote editing:" +
                               "\nresponseText=" + jqXHR.responseText +
                               "\n\nWe can verify the server response and return false in case of" +
                               " error response. return true confirm that the response is successful");
                         // we can verify the server response and interpret it do as an error
                         // in the case we should return false. In the case onError will be called
                         return true;
                     },
                     onError: function (rowid, jqXHR, textStatus) {
                         // the function will be used as "errorfunc" parameter of editRow function
                         // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow)
                         // and saveRow function
                         // (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#saverow)
                         alert("in onError used only for remote editing:" +
                               "\nresponseText=" + jqXHR.responseText +
                               "\nstatus=" + jqXHR.status +
                               "\nstatusText" + jqXHR.statusText +
                               "\n\nWe don't need return anything");
                     },
                     afterSave: function (rowid) {
                         alert("in afterSave (Submit): rowid=" + rowid + "\nWe don't need return anything");
                     },
                     afterRestore: function (rowid) {
                         alert("in afterRestore (Cancel): rowid=" + rowid + "\nWe don't need return anything");
                     },
                     delOptions: {
                         // 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 (rp_ge, rowid) {
                             // we can use onclickSubmit function as "onclick" on "Delete" button
                             alert("The row with rowid=" + rowid + " will be deleted");

                             // reset processing which could be modified
                             rp_ge.processing = true;

                             // delete row
                             $(this).delRowData(rowid);
                             $("#delmod" + $(this)[0].id).hide();

                             if ($(this)[0].p.lastpage > 1) {
                                 // reload grid to make the row from the next page visable.
                                 // TODO: deleting the last row from the last page which number is higher as 1
                                 $(this).trigger("reloadGrid", [{ page: $(this)[0].p.page }]);
                             }

                             return true;
                         },
                         processing: true // !!! the most important step for the "local" editing
                         //     skip ajax request to the server
                     }
                 }
             }

さて、問題:

コントローラーの呼び出し - アクションを指定する場所は? [編集] をクリックしても何も起こりません。自分のコントローラーのアクションを呼び出して、jqgrid ダイアログの代わりに自分のダイアログをポップアップしたいのです。

ガイドしてください。

4

1 に答える 1