1

我目前有一个网格,它在单击时将所选行的数据存储在数组中。此方法工作得很好,但是我正在尝试更改它,以便可以使用复选框选择多行并能够将所有日期存储在我的数组中。基本上,我不想在我的数组中一次添加一行,而是希望能够在其中添加多行。我不知道你们是否关注我,但请查看我的代码,以便我们找到一种方法来做到这一点。

这里是,

Javascript:

$('#GridBindContact').on('iggridselectionactiverowchanged', function (event, args) {
  $("#PrimaryKey").val(args.row.element[0].cells[1].textContent);
  $("#ContactToBind_Numcon").val(args.row.element[0].cells[1].textContent);
  $("#ContactToBind_FullName").val(args.row.element[0].cells[2].textContent + ' ' +     args.row.element[0].cells[3].textContent);
  $("#ContactToBind_Titcon").val(args.row.element[0].cells[4].textContent);
  $("#ContactToBind_Tel1con").val(args.row.element[0].cells[5].textContent);
  $("#ContactToBind_Tel2con").val(args.row.element[0].cells[6].textContent);
  $("#ContactToBind_Emailcon").val(args.row.element[0].cells[7].textContent);
  $("#ContactToBind_NumEmployees").val(args.row.element[0].cells[8].textContent);
  $("#ContactToBind_NameEmployees").val(args.row.element[0].cells[9].textContent);
  $("#ContactToBind_Added").val(true);
  $(".ui-button-text").trigger("click");
});

在我看来 :

@(Html.Infragistics.Grid(Of Contact)(Model.Results).ID("GridBindContact").
    AutoGenerateColumns(False).
    Width("100%").
    Height("400px").
    ResponseDataKey("Results").
    Columns(Sub(column)
            column.For(Function(e) e.Numcon).Template("${Numcon}").HeaderText("Num")
            column.For(Function(e) e.Pnmcon).Template("${Pnmcon}").HeaderText("Pnm").Width("10%")
            column.For(Function(e) e.Namemcon).Template("${Namecon}").HeaderText("Name").Width("15%")
            column.For(Function(e) e.Titcon).Template("${Titcon}").HeaderText("Title").Width("20%")
            column.For(Function(e) e.Tel1con).Template("${Tel1con}").HeaderText("Tel1")
            column.For(Function(e) e.Tel2con).Template("${Tel2con}").HeaderText("Tel2")
            column.For(Function(e) e.Emailcon).Template("${Emailcon}").HeaderText("Email")
            column.For(Function(e) e.NumEmployees).HeaderText("Num Emp")
            column.For(Function(e) e.NameEmployees).HeaderText("Name Emp")
            End Sub).
    Features(Sub(features)
             features.Sorting().Type(OpType.Local)
             features.RowSelectors.EnableCheckBoxes(True).RowSelectorsColumnWidth("50px").EnableRowNumbering(False)
             features.Selection().Mode(SelectionMode.Row).MultipleSelection(True).AddClientEvent("activeRowChanging", "activeRowChanging")
             features.Updating().EditMode(GridEditMode.None).EnableAddRow(False).EnableDeleteRow(False)
             End Sub).Render())

<form action="#" id="ajaxForm" method="post">
    @Html.HiddenFor(Function(x) x.PrimaryKey)
    @Html.HiddenFor(Function(x) x.ContactToBind.Numcon)
    @Html.HiddenFor(Function(x) x.ContactToBind.FullName)
    @Html.HiddenFor(Function(x) x.ContactToBind.Titcon)
    @Html.HiddenFor(Function(x) x.ContactToBind.Tel1con)
    @Html.HiddenFor(Function(x) x.ContactToBind.Tel2con)
    @Html.HiddenFor(Function(x) x.ContactToBind.Emailcon)
    @Html.HiddenFor(Function(x) x.ContactToBind.NumEmployees)
    @Html.HiddenFor(Function(x) x.ContactToBind.NameEmployees)
</form>

我已经添加了在我的网格中有复选框的功能,但还没有处理它们!

///////////////////////////////////////// //////////////////////////////////

一点点编辑,所以我可以清理一些东西

让我尝试详细说明一下我希望能够做什么。我希望能够将行数组中检查的所有行中的数据作为批处理添加。也就是说,假设我检查了三行。当我按下“确定”按钮时,它应该将所有三行的信息存储在我的数组中。

如果全部成功,我的数组应该有三个“元素”。例如,array[0] 将包含来自被检查的第一行的数据。这将允许我访问每个单元格并将它们的“textContent”存储在“ContactToBind”中,这是我目前用来存储每个单元格信息的内容。

我希望这能澄清一点!

非常感谢你的帮助。

纪尧姆

4

1 回答 1

2

您可以使用.igGrid( "allRows" );获取 Grid 中的所有行,将其保存在名为"myRows". 然后编写javascript代码遍历"myRows"你得到的.igGrid( "allRows" )并检查每一行组合框的值。如果当前行的组合框“选中”,则将此当前行放入数组中。在循环结束时,您将检查数组中的所有行。

如果您不知道如何遍历"allRows"存储在"myRows"变量中的对象,请使用console.log(myRows)并检查浏览器控制台窗口中的对象结构。您将能够看到如何到达复选框列,它会是这样的,但我不确定请使用 console.log 检查自己:

for(var i = 0 ; i < myRows.length ; i ++ )
{
myRows[i].cells....(select the checked combobox)
if yes then store myRows[i] in your array;
}
于 2014-09-08T10:09:21.020 回答