【问题标题】:Split into Multiple textboxes for single colmn in JQGrid拆分为 JQGrid 中单列的多个文本框
【发布时间】:2016-03-15 14:02:54
【问题描述】:

我在 MVC 应用程序中使用 JQgrid。我得到了这样的要求,一列应该在添加向导中分成 3 个文本框。默认情况下,它是一个文本框。 让我知道任何相同的解决方案。

我需要在 3 个文本框中输入邮政编码,保存时我需要合并所有内容并添加到单个字段 这是代码:

var mydata = [{
    zip : "23-12-13",
    name: "Toronto",
    country: "Canada",
    continent: "North America"
}, {
zip : "23-12-13",
    name: "New York City",
    country: "USA",
    continent: "North America"
}, {
zip : "23-12-13",
    name: "Silicon Valley",
    country: "USA",
    continent: "North America"
}, {
zip : "23-12-13",
    name: "Paris",
    country: "France",
    continent: "Europe"
}]

$("#grid").jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ['Zip/Postal',"Name", "Country", "Continent"],
    colModel: [
        {name:'Zip/Postal',index:'zip', editable: true,},
    {
        name: 'name',
        index: 'name',
        editable: true,
    }, {
        name: 'country',
        index: 'country',
        editable: true,
    }, {
        name: 'continent',
        index: 'continent',
        editable: true,
    }],
    pager: '#pager',
    'cellEdit': true,
    'cellsubmit' : 'clientArray',
    editurl: 'clientArray',
 pager: "#jqGridPager",
            loadComplete: function () {
 }
        }).navGrid('#jqGridPager',
            // the buttons to appear on the toolbar of the grid
            { Add  : true },
 {
                url: '@Url.Action("Add", "Add")',
                height: 'auto',
        modal: true,
                addCaption: "Add: ",
                closeAfterAdd: false,
                recreateForm: true,
                beforeShowForm: function () {

}
        afterShowForm:function () {

}

【问题讨论】:

  • 请提供代码,如果你能提供一个使用 JSFIDDLE 的问题演示会更有帮助
  • 代码附在上面

标签: jqgrid free-jqgrid


【解决方案1】:

更新:

我更改了代码以显示模式而不是内联编辑。

    <table id="grid">
</table>
<div id="customDialog" title="Custom Dialog" style="display: none;">
  <p>
  <label for="zipField1">Zip1:</label>
    <input id="zipField1" />
  </p>
   <p>
   <label for="zipField2">Zip2:</label>
    <input id="zipField2" />
   </p>
    <p>
     <label for="zipField3">Zip3:</label>
    <input id="zipField3" />
    </p>
   <p>
    <label for="Name">Name:</label>
    <input id="Name" />
   </p>
   <p>
   <label for="country">Country:</label>
    <input id="country" />
   </p>
   <p>
    <label for="continent">Continent:</label>
    <input id="continent" />
   </p> 
   <p>
   <button>
   Submit
   </button>
   </p>
</div>

var mydata = [{
  zip: "23-12-13",
  name: "Toronto",
  country: "Canada",
  continent: "North America"
}, {
  zip: "23-12-13",
  name: "New York City",
  country: "USA",
  continent: "North America"
}, {
  zip: "23-12-13",
  name: "Silicon Valley",
  country: "USA",
  continent: "North America"
}, {
  zip: "23-12-13",
  name: "Paris",
  country: "France",
  continent: "Europe"
}];

$("#grid").jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ['Edit','Zip/Postal', "Name", "Country", "Continent"],
    colModel: [
      {name: "actions", template: "actions", width: 60 },
      {name: 'Zip/Postal', editable: true},
      {name: 'name', editable: true}, 
      {name: 'country',  editable: true}, 
      {name: 'continent', editable: true}
    ],
    pager: true,
    navOptions: {
      edit: false,
      add: false,
      del: false,
      searchtext: "Search",
      refreshtext: "Reload",
      iconsOverText: true
    },
    inlineNavOptions: {
      edit: false,
      add: false,
      del: false
    },
    searching: {
      overlay: false,
      multipleSearch: true,
      closeAfterSearch: true,
      closeOnEscape: true,
      showQuery: true
    },
    actionsNavOptions: {
     delbutton: false,
     editbutton: false,
     addbutton: false,
     editGridicon: "ui-icon-pencil",
     editGridtitle: "Edit Grid",
       custom: [{
         action: "editGrid", position: "first", onClick: function (options) {
          var rowData = $(this).getRowData(options.rowid);
          $("#customDialog").dialog('open');
         }
         }]
    }
  }).jqGrid('navGrid');

    $("#customDialog").dialog({
        title: "custom dialog",
      autoOpen: false,
      close: function () {
                $(this).dialog( 'close' );
      }
    });

  function editGrid() {

  }

查看更新的小提琴:https://jsfiddle.net/y3llowjack3t/xpzdn4j8/

【讨论】:

  • 我正在查看添加窗口弹出窗口,而不是网格中的内联。当添加弹出窗口显示时,我需要显示 3 个文本框,而不是一列的单个文本框
  • @Sharath 您可以创建一个包含您的字段的自定义模式并使用自定义按钮打开该自定义模式,请查看小提琴 - 单击铅笔查看模式jsfiddle.net/y3llowjack3t/xpzdn4j8/2
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-28
  • 1970-01-01
  • 2021-01-30
  • 2015-09-08
  • 1970-01-01
  • 1970-01-01
  • 2021-05-09
相关资源
最近更新 更多