在jqgrid中添加后如何选择和定位插入的行?

时间:2012-09-13 07:28:49

标签: asp.net-mvc-3 jqgrid

我有一个工作正常的jqgrid。但是,我想在添加它之后选择并将自己定位在插入的行上。我希望插入的行能够正确排序并放在jqgrid中。

现在我只设法选择插入的行,但它没有在网格中正确排序。插入的行显示在我当前所在页面的顶部。

以下是我的代码示例,其中create function在jqgrid中插入一个新行。

$(document).ready(function () {
        $('#jqgProducts').jqGrid({
            //url from wich data should be requested
            url: '@Url.Action("DynamicGridData")',


            //type of data
            datatype: 'json',
            mytype: 'POST',
            //url access method type
            //jsonReader:{repeatitems : false, id: "cSfPT"},
            //columns names
            colNames: ['Šifra pošte', 'Naziv pošte', 'Napomena'],
            //columns model
            colModel: [
                        { name: 'cSfPT', index: 'cSfPT', align: 'left', width: '100px', key: true, editable: true, search: true

                         },

                        { name: 'cNzPt', index: 'cNzPt', align: 'left', width: '200px', editable: true, edittype: 'text',
                             },

                        { name: 'cNapomena', index: 'cNapomena', align: 'left', width: '400px', 

                         editrules: { required: false} }
                      ],
            //pager for grid
            pager: '#jqgpProducts',
            //number of rows per page
            rowNum: 10,
            //initial sorting column
            sortname: 'cSfPT',
            //initial sorting direction
            sortorder: 'asc',
            //we want to display total records count
            viewrecords: true,
            //grid height
            height: '300px',
            width : 1000,
            rownumbers: true,
            //scroll: true,
            cellEdit:true,
            cellurl: 'Edit',


            loadComplete: function () {
                if (idToSelect) {
                $(this).jqGrid('setSelection', idToSelect);
                //$("#" + $.jgrid.jqID(idToSelect)).effect("highlight", {}, 3000);
                idToSelect = undefined;
                }
            }

 $('#jqgProducts').jqGrid('navGrid', '#jqgpProducts',
            { add: true,
              del: true,
              edit:true, 
              search: true

               },

{width: '450', url: '@Url.Action("Create")', closeAfterAdd: true, 

            closeAfterEdit: true,

            reloadAfterSubmit: false,

            afterSubmit: function (response) {
                return [true, '', response.responseText];
            },


            addedrow: "last", // add new row at the end of grid

             afterComplete: function (response, postdata) {

                var gridId = this.gbox.substr(6);

                $('#' + gridId).jqGrid('setSelection', postdata.id);
             },




            afterSubmit: function (response) {

            idToSelect = response.responseText;
            return [true, '', response.responseText];
            }

       };
      );
    });

我将不胜感激任何帮助。

1 个答案:

答案 0 :(得分:0)

您可以设置客户端:

sortname: 'yourSortingColum'
sortorder: 'asc' || sortorder:'desc'