传递来自网格的所有行,这些行在特定列中具有特定值

时间:2014-02-19 10:42:00

标签: asp.net ext.net

我有一个名为sampleGrid的Ext GridPanel,它有一些列。其中一个名为 IsAssigned ,持有 bool值

我有一个分机按钮。当我单击它时,我想传递所有具有IsAssigned列值false的行。

我可以传递所有网格行,

见下面的代码示例,

 <ext:Button ID="btnSave" runat="server" Text="Save"
                                Icon="Accept">
                                <DirectEvents>
                                    <Click OnEvent="btnSave_Click">
                                    <ExtraParams>
                                    <ext:Parameter Name="rows" Value="Ext.encode(#{sampleGrid}.getRowsValues())"
                                     Mode="Raw" ></ext:Parameter>
                                    </ExtraParams>
                                    </Click>
                                </DirectEvents>
                            </ext:Button> 

此处 Ext.encode(#{sampleGrid} .getRowsValues())将传递所有行。但我想只传递 IsAssigned 列值为false的行。

isAssigned列代码:

 <ext:CheckColumn ColumnID="chkSelect" DataIndex="IsAssigned" MenuDisabled="true"
                                            Sortable="true" Width="30px" Editable="true">
                                        </ext:CheckColumn>

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我不确定这是否是最佳解决方案但请尝试。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>

        function Test() {
            var jsondata = Ext.encode(App.grd.getRowsValues());
            alert("{dt:" + jsondata + "}");
            var mynewitems = {};
            var myobj = JSON.parse('{"dt":' + jsondata +'}');


            for (var i = 0; i < myobj.dt.length; i++) {
                alert(myobj.dt[i].data2);
                if (myobj.dt[i].data2 == true) { myobj.dt.splice(i, 1); }
            }
            alert(myobj);
            return myobj;
        }
    </script> 

</head>
<body>
    <form id="form1" runat="server">
        <ext:ResourceManager runat="server"></ext:ResourceManager>


        <ext:Button ID="btnSave" runat="server" Text="Save"
                                Icon="Accept">
                                <DirectEvents>
                                    <Click OnEvent="btnSave_Click">
                                    <ExtraParams>
                                    <ext:Parameter Name="rows" Value="Test()"
                                     Mode="Raw" ></ext:Parameter>
                                    </ExtraParams>
                                    </Click>
                                </DirectEvents>
                            </ext:Button> 

  <ext:GridPanel runat="server" ID="grd" Height="300" Layout="FitLayout">

            <Store>
                <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model ID="Model1" runat="server">
                            <Fields>
                                <ext:ModelField Name="data0"></ext:ModelField>
                                <ext:ModelField Name="data1"></ext:ModelField>
                                <ext:ModelField Name="data2"></ext:ModelField>
                            </Fields>
                        </ext:Model>
                    </Model>

                </ext:Store>
            </Store>
            <ColumnModel>

                <Columns>
                    <ext:Column ID="Column1" runat="server" DataIndex="data0" Text="data0"></ext:Column>
                    <ext:Column ID="Column2" runat="server" DataIndex="data1" Text="data1"></ext:Column>
                    <ext:CheckColumn ID="CheckColumn1" runat="server" DataIndex="data2" Text="data2"></ext:CheckColumn>
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </form>
</body>
</html>

代码背后;

protected void Page_Load(object sender, EventArgs e)
    {
       grd.GetStore().DataSource = GetData();
       grd.DataBind();
    }

    public  void btnSave_Click(Object sender,DirectEventArgs e)
    {

        string js = e.ExtraParams["rows"].ToString();



            X.Msg.Alert("aaa", js).Show();

    }
    private object[] GetData()
    {

        return new object[] { 
            new object[] { "test1", "test1", true },
            new object[] { "test2", "test2", false },
            new object[] { "test3", "test3", false } };

    }

答案 1 :(得分:1)

伙计们我使用filterRecord完成了它。

<ext:Parameter Name="rows" Value="Ext.encode(#{sampleGrid}.getRowsValues(
                                            {
                                            filterRecord : function (record) {
                                            return (record.data.IsAssigned==false); }
                                            })
                                            )" Mode="Raw" >
</ext:Parameter>