开发者

asp.net mvc 2 jqgrid add record

i am trying to display the 'add new record' display in jqgrid but it does not show up?

  <script type="text/javascript">
    jQuery(document).ready(function () {

        $("#addBtn").click(function () {
            $("#list").jqGrid('editGridRow', "new", { height: 280, reloadAfterSubmit: false });
        });


      var lastsel;
      $("#list").jqGrid({
          url: '/Home/DynamicGridData/',
          datatype: 'json',
          mtype: 'GET',
          colNames: ['IdNr', 'Id', 'FirstName', 'LastName'],
          colModel: [
      { name: 'IdNr', index: 'IdNr', width: 40, align: 'left',
  开发者_C百科        editable: true, editrules: { edithidden: true }, hidden: true
      },
      { name: 'Id', index: 'Id', width: 40, align: 'left',
          editable: false
      },
      { name: 'FirstName', index: 'FirstName', width: 200, align: 'left', editable: true, edittype: 'text', editoptions: { size: 20, maxlength: 30} },
      { name: 'LastName', index: 'LastName', width: 300, align: 'left', editable: true, edittype: 'text', editoptions: { size: 20, maxlength: 30}}],
          onSelectRow: function (id) {
              if (id && id !== lastsel) {
                  jQuery('#list').restoreRow(lastsel);
                  jQuery('#list').editRow(id, true);
                  jQuery("#grid_id").editGridRow(id, options); 
                    lastsel = id;
              }
          },
          editurl: "/Home/GridSave",
          pager: jQuery('#pager'),
          rowNum: 10,
          rowList: [5, 10, 20, 50],
          sortname: 'Id',
          sortorder: "desc",
          viewrecords: true,
          imgpath: '/content/themes/steel/images',
          caption: 'Employees'
      });



  });



</script>  


<table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>


How you can see here the code which you posted in general work.

I suppose that you don't included "Form Edit" module or "Common" module during downloading of the jqGrid. In you open jquery.jqGrid.min.js file which you use you can examine the comment line after the beginning of the file. You should find at list the following: grid.base.js, grid.common.js and grid.formedit.js after "Modules:. I recommend you always include "Formatter" module also. The common rule is: better include too many modules as too few.

Small additional remarks: You should not use since a long time deprecated parameter imgpath. Default parameters like align: 'left' or editable: false can be also emitted. The <table> definition in the HTML code can be reduced to <table id="list"></table>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜