单击extjs顶部栏上添加的按钮,获取网格中行的列索引

时间:2013-08-07 19:00:22

标签: ext.net

如何通过索引获取所有列。就像我不知道我有多少列以及它们的DataIndex值是什么,然后如何获得它们。

实际上我想清除单元格,这就是为什么要查找行中每列的索引。如果有任何其他方法来清除行数据,请帮助。 目前我通过使用下面的代码获得行索引

  

var record = grid.getSelectionModel()。getSelection()[0];

     

var index = store.indexOf(record);

现在我要做的第一件事就是在点击按钮上清除所选行中单元格的内容,其次我想获得所选行内的列的索引,并使用它们的索引为它们设置任何值。

2 个答案:

答案 0 :(得分:0)

我想如果单元格中出现特定值,您实际上想要更改某些内容 - 在网格添加中执行此操作:

 <View>
     <ext:GridView runat="server" >
             <GetRowClass Fn="getRowClass" />
     </ext:GridView>
</View>   

然后在getRowClass中你可以为每一行做你想做的事情,如:

function getRowClass(record) {
    var someVar = record.data.<columnIndex>;
    if (someVar == <someValue>) {
       do something
    }}

答案 1 :(得分:0)

请参阅按钮处理程序。

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            Store store = this.GridPanel1.GetStore();
            store.DataSource = new object[] 
            { 
                new object[] { "test1", "test2", "test3" },
                new object[] { "test4", "test5", "test6" },
                new object[] { "test7", "test8", "test9" }
            };
        }
    }
</script>

<!DOCTYPE html>
<html>
<head runat="server">
    <title>Ext.NET v2 Example</title>

    <script>
        var setRecord = function (record, value) {
            var i,
                fields = record.fields.items,
                field;

            record.beginEdit();

            for (i = 0; i < fields.length; i++) {
                field = fields[i].name;

                if (field !== record.idProperty) {
                    record.set(field, value);
                }
            }

            record.endEdit();
        };

        var clear = function () {
            var grid = App.GridPanel1,
                selection = grid.getSelectionModel().getSelection(),
                i;

            for (i = 0; i < selection.length; i++) {
                setRecord(selection[i], "");
            }
        };

        var set = function () {
            var grid = App.GridPanel1,
                selection = grid.getSelectionModel().getSelection(),
                i;

            for (i = 0; i < selection.length; i++) {
                setRecord(selection[i], "new");
            }
        };
    </script>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />

        <ext:Button runat="server" Text="Clear" Handler="clear" />

        <ext:Button runat="server" Text="Set" Handler="set" />

        <ext:GridPanel ID="GridPanel1" runat="server">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test1" />
                                <ext:ModelField Name="test2" />
                                <ext:ModelField Name="test3" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Test1" DataIndex="test1" />
                    <ext:Column runat="server" Text="Test2" DataIndex="test2" />
                    <ext:Column runat="server" Text="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>        
    </form>
</body>
</html>