在客户端更改igGrid DataSource

时间:2014-03-06 23:02:46

标签: jquery asp.net-mvc-4 binding infragistics iggrid

我有一个简单的MVC4页面,其中包含Infragistics 2013.2 Combo(igCombo)和一个Grid(igGrid)。

我的控制器在Model中返回一个具有多个DataTable(“table1”,“table2”,“table3”等)的DataSet,并且组合中填充了来自ViewBag的表名列表(“table1”等)。

我想根据组合中选定的文本(表格)更改网格但不会发生。更改组合时,网格不会从初始表更改。

根据Infragistics,这应该是可能的:{Binder to DataSet“会话中的Binding igGrid to 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())

0 个答案:

没有答案