The official release of Ext.NET Mobile is now available. Ext.NET Mobile is an ASP.NET component framework for building Phone and Tablet specific mobile web applications. Read More

[CLOSED] How to check the items in the GridPanel

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] How to check the items in the GridPanel

    Hi Community !

    Please check the code sample below:

    
    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = new object[]
                {
                    new object[] { 1, "3m Co", "Blue"},
                    new object[] { 2, "Alcoa Inc", "Blue"},
                    new object[] { 3, "Altria Group Inc", "Red" },
                    new object[] { 4, "American Express Company", "Red"},
                    new object[] { 5, "American International Group, Inc.", "Red" },
                    new object[] { 6, "AT&T Inc.", "Yellow" },
                    new object[] { 7, "Boeing Co.", "Yellow" },
                    new object[] { 8, "Caterpillar Inc.", "Green" },
                    new object[] { 9, "Citigroup, Inc.", "Green" },
                    new object[] { 10, "E.I. du Pont de Nemours and Company",  "Green" }
                };
    
                this.Store1.DataBind();
            }
       }
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            try
            {
                //var record = Store1.GetById("1");
                //I can't find the way to make it work.
                //GridPanelPuntosPartidas.GetSelectionModel().Select(??, true);
                
                GridPanel1.GetSelectionModel().Select(1, true);
            }
            catch (Exception)
            {
            }
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    
    <head id="Head1" runat="server">
        <title>GridPanel with Checkbox Selection Model - Ext.NET Examples</title>
    </head>
    
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Viewport ID="ViewPort1" runat="server" Layout="BorderLayout">
                <Items>
                   
                    <ext:GridPanel ID="GridPanel1" runat="server"
                            Title="Company List"
                            LockText="Bloquear"
                            UnlockText="Desbloquear"
                            MarginSpec="0 5 5 0"
                            SelectionMemory="false"
                            ForceFit="true"
                            Region="Center"
                            Border="False"
                            Frame="true"
                            EnableColumnHide="true">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:ToolbarFill ID="ToolbarFill1" runat="server"></ext:ToolbarFill>
                                    <ext:Button ID="Button1" runat="server" Icon="Find" Text="Find">
                                        <DirectEvents>
                                            <Click OnEvent="Button1_Click">
                                            </Click>
                                        </DirectEvents>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>                    
                        
                        <Store>
                            <ext:Store ID="Store1" runat="server" PageSize="10">
                                <Model>
                                    <ext:Model ID="Model1" runat="server" IDProperty="ID">
                                        <Fields>
                                            <ext:ModelField Name="ID" />
                                            <ext:ModelField Name="Name" />
                                            <ext:ModelField Name="Colour" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
    
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:Column ID="Column1" runat="server" Text="Company" Width="160" DataIndex="Name" Flex="1" />
    
                                <ext:Column ID="Column2" runat="server" Text="Colour" Width="160" DataIndex="Colour" Flex="1" />
                            </Columns>
                        </ColumnModel>
    
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" Mode="Multi" />
                        </SelectionModel>
    
                    </ext:GridPanel>
    
                </Items>
            </ext:Viewport>
        </form>
      </body>
    </html>
    I get a set of records through consulting the database, these records should correspond
    to the items selected in the GridPanel.

    But what I've tried hasn't worked and I don't know how to select the right item without
    having to go through the store.

    var record = Store1.GetById("1");

    I can't find the way to make it work.

    GridPanelPuntosPartidas.GetSelectionModel().Select (??, true);

    Thank you for your help!
    Last edited by fabricio.murta; Dec 11, 2017 at 6:49 PM.
  2. #2
    Hello Mauricio!

    Wouldn't be the case for you to submit the grid panel's selected items only? But I'm not 100% sure I understand your needs, it seems there could be the involvement of two but not just one grid panel, maybe?

    - Submitting Grid Panel selected entries examples in Examples Explorer

    Anyway, I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi Fabricio !!

    I think my choice of words was very confused, sorry about that.

    In The GridPanel, when we use “Find” filter bottom we get a set of records how you can see in this example:

    Click image for larger version. 

Name:	GridPanel with GridFilters 2.JPG 
Views:	1 
Size:	50.8 KB 
ID:	25087

    But the filter is not done correctly showing all the records and not filtering the ones we are looking for, hope that now my request is better understood, thank you in advance for your help.

    Saludos
    Mauricio
  4. #4
    Hello Mauricio!

    I'm still a little lost, but I'll go with my best shot.

    In your code you just try to select an entry when the 'filter' button is hit. But you say the server should return the entries filtered. The button should somehow send the filter pattern or have a filter argument (which we could see as "record with ID 1" by your current implementation).

    So... Maybe what you want is, server-side, perform a filter like in this example, Find '3m Co' button (right of the paging toolbar)?
    - GridFilters - Local

    In the example above, it does set the filter remotely but the filter acts over data previously loaded (thus cached client-side).

    My thought is that, in your case, you just want the button to do all local (a listener instead of a direct event to the filter button) and then let remote filtering kick in as in the example next to the previously linked example:
    - GridFilters - Remote

    Well, that would be my best shot trying to understand what you need! Hoping it to be more accurate now.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Aloha Fabricio !!

    Third time lucky, we hope. lol

    Through a SQL i get a set of tuples, for our example I got just a single tuple (it could be from 0 to n)

    DataTable theDatatable = SQL
    
    foreach DataRow theDataRow in DataTable.rows
    {
       var record = Store1.GetById(theDataRow["ID"]);
    
       // How can I check the row ?
       // GridPanel1.GetSelectionModel().Select( ???, true);
    }
    
    My solution was to go through GridPanel/Store for each tuple, now my question is: 
    
    Is there a way to select dynamic or faster selection? 
    
    forech DataRow theDataRow in DataTable.rows
    {
       foreach Rows theRows in GridPanel.Rows
       {
          if (theDataRow["ID"] == GridPanel.Rows.Columna(id))
          {
            theRows.Chequed = true;
          }
       }
    }
    Kind Regards,

    Saludos
    Mauricio
    Last edited by fabricio.murta; Dec 12, 2017 at 10:17 AM.
  6. #6
    Hi Fabricio !!

    Have you´ve been able to analyze my issue? I have to assume it's not possible?

    Thank you anyway!

    Saludos
    Mauricio
  7. #7
    Hello Mauricio! Sorry for the long delay! I couldn't get the very problem and solution you need in this case, I'll try another crack in it, hopefully now I get it right.
    Fabrício Murta
    Developer & Support Expert
  8. #8
    And hello again! What about this?

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Linq" %>
    
    <script runat="server">
    
        public Record[] data = new Record[]
        {
            new Record(21, "3m Co", "Blue"),
            new Record(22, "Alcoa Inc", "Blue"),
            new Record(23, "Altria Group Inc", "Red"),
            new Record(24, "American Express Company", "Red"),
            new Record(25, "American International Group, Inc.", "Red"),
            new Record(26, "AT&T Inc.", "Yellow"),
            new Record(27, "Boeing Co.", "Yellow"),
            new Record(28, "Caterpillar Inc.", "Green"),
            new Record(29, "Citigroup, Inc.", "Green"),
            new Record(210, "E.I. du Pont de Nemours and Company",  "Green")
        };
    
        public class Record
        {
            public int Id { get; set; }
            public string Company { get; set; }
            public string Color { get; set; }
    
            public Record(int i, string c, string l)
            {
                Id = i;
                Company = c;
                Color = l;
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = data;
    
                this.Store1.DataBind();
            }
        }
    
        // The linq select here emulates a custom database selection where a subset of
        // the database's "data" will be returned.
        protected void Select_American(object sender, DirectEventArgs e)
        {
            GridPanel1.GetSelectionModel().ClearSelection();
    
            var data_to_select = data.Where(d => d.Company.StartsWith("America")).Select(d => d.Id);
    
            foreach (var id in data_to_select)
            {
                GridPanel1.GetSelectionModel().Select((object)id, true);
            }
        }
    
        protected void Select_Blue(object sender, DirectEventArgs e)
        {
            GridPanel1.GetSelectionModel().ClearSelection();
    
            var data_to_select = data.Where(d => d.Color == "Blue").Select(d => d.Id);
            foreach (var id in data_to_select)
            {
                GridPanel1.GetSelectionModel().Select((object)id, true);
            }
        }
    
        protected void Select_Red(object sender, DirectEventArgs e)
        {
            GridPanel1.GetSelectionModel().ClearSelection();
    
            var data_to_select = data.Where(d => d.Color == "Red").Select(d => d.Id);
            foreach (var id in data_to_select)
            {
                GridPanel1.GetSelectionModel().Select((object)id, true);
            }
        }
    
    </script>
    
    <!DOCTYPE html>
    
    <html>
    
    <head id="Head1" runat="server">
        <title>GridPanel with Checkbox Selection Model - Ext.NET Examples</title>
    </head>
    
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Viewport ID="ViewPort1" runat="server" Layout="BorderLayout">
                <Items>
                   
                    <ext:GridPanel ID="GridPanel1" runat="server"
                            Title="Company List"
                            LockText="Bloquear"
                            UnlockText="Desbloquear"
                            MarginSpec="0 5 5 0"
                            SelectionMemory="false"
                            ForceFit="true"
                            Region="Center"
                            Border="False"
                            Frame="true"
                            EnableColumnHide="true">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:ToolbarFill ID="ToolbarFill1" runat="server"></ext:ToolbarFill>
                                    <ext:Button ID="Button1" runat="server" Icon="FlagUs" Text="Select 'American'" OnDirectClick="Select_American" />
                                    <ext:Button ID="Button2" runat="server" Icon="RosetteBlue" Text="Select blue" OnDirectClick="Select_Blue" />
                                    <ext:Button ID="Button3" runat="server" Icon="Stop" Text="Select red" OnDirectClick="Select_Red" />
                                </Items>
                            </ext:Toolbar>
                        </TopBar>                    
                        
                        <Store>
                            <ext:Store ID="Store1" runat="server" PageSize="10">
                                <Model>
                                    <ext:Model ID="Model1" runat="server" IDProperty="Id">
                                        <Fields>
                                            <ext:ModelField Name="Id" />
                                            <ext:ModelField Name="Company" />
                                            <ext:ModelField Name="Color" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
    
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:Column ID="Column1" runat="server" Text="Company" Width="160" DataIndex="Company" Flex="1" />
    
                                <ext:Column ID="Column2" runat="server" Text="Colour" Width="160" DataIndex="Color" Flex="1" />
                            </Columns>
                        </ColumnModel>
    
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" Mode="Multi" />
                        </SelectionModel>
    
                    </ext:GridPanel>
    
                </Items>
            </ext:Viewport>
        </form>
      </body>
    </html>
    The "trick" here is, cast the record ID as an object, so that Ext.NET emits a query to fetch the record from the ID, instead of assuming you want to select by the row number in the grid.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  9. #9
    Hi Fabrício !

    Thanks for your reply, you're providing a great support ! Keep up the great work.

    Please close the thread.

    Saludos
    Mauricio.
  10. #10
    Hello Mauricio!

    Thank you very much for the compliment, it's really rewarding!

    I guess this means the code above really reflected what you wanted to achieve, right? If so, glad we could help!
    Fabrício Murta
    Developer & Support Expert
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: Dec 22, 2014, 5:05 PM
  2. [CLOSED] check all MultiCombo items from javascript
    By prost in forum 2.x Premium Help
    Replies: 4
    Last Post: Apr 15, 2013, 12:55 PM
  3. Replies: 2
    Last Post: Jul 30, 2012, 5:57 PM
  4. How we can check Duplicate entries in Gridpanel?
    By NishaLijo in forum 1.x Help
    Replies: 3
    Last Post: Jun 03, 2011, 10:57 AM
  5. Replies: 2
    Last Post: Mar 21, 2010, 2:18 PM

Posting Permissions