我有一个简单的 MVC4 页面,其中包含 Infragistics 2013.2 组合 (igCombo) 和网格 (igGrid)。
我的控制器在模型中返回一个具有多个 DataTable(“table1”、“table2”、“table3”等)的 DataSet,并且该组合填充了来自 ViewBag 的表名称列表(“table1”等)。
我想根据组合中选定的文本(表格)更改网格,但它没有发生。当更改组合时,网格不会从初始表中更改。
根据 Infragistics,这应该是可能的:在“Binding to DataSet”会话中将 igGrid 绑定到 DataTable 。
我的控制器:
public PartialViewResult Test1()
{
DataSet dts = new DataSet();
//table1
DataSet tempDts = "select COL1, COL2, COL3 from table1";
tempDts.Tables[0].TableName = "table1";
dts.Tables.Add(tempDts.Tables[0].Copy());
//table2
DataSet tempDts = "select COL4, COL5, COL6, COL7, COL8 from table2";
tempDts.Tables[0].TableName = "table2";
dts.Tables.Add(tempDts.Tables[0].Copy());
//table3
DataSet tempDts = "select COL9, COL10 from table3";
tempDts.Tables[0].TableName = "table3";
dts.Tables.Add(tempDts.Tables[0].Copy());
String[] listTables = new String[] { "table1", "table2", "table3" };
ViewBag.Combo = listTables;
return PartialView(dts);
}
我的Javascript:
$(function () {
$(document).delegate("#combo1", "igcomboselectionchanged", function (evt, ui) {
//At debug I confirmed that ui.items[0].value is "table2"
$("#grid1").igGrid("option", "dataMember", ui.items[0].value);
$("#grid1").igGrid("dataBind");
});
});
我的网格:
@(Html.Infragistics()
.Grid<DataTable>()
.ID("grid1")
.AutoGenerateColumns(true)
.Features(features =>
{
features.Resizing();
features.RowSelectors().RowSelectorsColumnWidth("25px").EnableRowNumbering(false);
features.Selection().Mode(SelectionMode.Row).MultipleSelection(false);
features.Paging().PageSize(10);
})
.Height("100%")
.DefaultColumnWidth("150")
.DataMember("table1")
.DataSource(Model)
.DataBind()
.Render())