Loop through Filtered Data - Grid

13 posts, 0 answers
  1. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 24 Oct 2012 Link to this post

    Hi there

    I have a RadGrid that a user can apply filters to. Once they click on a submit button, I want to extract all filtered rows and then process the data from there.

    Is there a built in function to only retrieve the filtered data?

    Thank you.
  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 24 Oct 2012 Link to this post

    Hello Jako,

    Once you apply a data operation to RadGridView (filtering, grouping, sorting) the resulted view is stored in the ChildRows collection of the template. So you can access your rows from there.

    More information regarding this matter is available here: http://www.telerik.com/help/winforms/gridview-rows-rows-vs-childrows.html.
     
    Greetings,
    Stefan
    the Telerik team
    You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
  3. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 24 Oct 2012 Link to this post

    Thanks Stefan, that is great!
  4. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 29 Oct 2012 Link to this post

    Hi Stefan

    This seems to be for WinForms, I am using a web application with the AJAX controls.

    I can't seem to find how to implement the ChildRows using a RadGrid? I doesn't have any NestedViews, I just want to get the filtered rows from a RadGrid

    Thanks
  5. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 29 Oct 2012 Link to this post

    I have done a little hack as I couldn't find any way to just plainly get the filtered result. The itemCount is just to validate that its working.

    protected void uxSendMail_Click(object sender, EventArgs e)
    {
        int itemCount = 0;
     
        uxSitesGrid.AllowPaging = false;
        uxSitesGrid.Rebind();
     
        foreach (GridDataItem gridRow  in uxSitesGrid.Items)
        {
            itemCount += 1;
        }
     
        System.Windows.Forms.MessageBox.Show(itemCount.ToString());
     
        uxSitesGrid.AllowPaging = true;
        uxSitesGrid.Rebind();
    }
  6. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 29 Oct 2012 Link to this post

    Just another thing, when you have a checkbox as one of your columns, it loses its status when you page?

    Is there a way to keep the status accros paging?
  7. Eyup
    Admin
    Eyup avatar
    4014 posts

    Posted 31 Oct 2012 Link to this post

    Hi Jako,

    Please note that RadGrid does not preserve the selected items or the state of Template controls upon performing database operations. Therefore, although you will get the selected items successfully on any other server event, their state will reset when you fire a command regarding a datasource request.

    You could save the selected items in a collection variable and use it when necessary:
    http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-client-sorting-paging-grouping-filtering.html
    or
    http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-on-sorting.html

    I hope this will prove helpful.

    Kind regards,
    Eyup
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  8. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 31 Oct 2012 Link to this post

    Hi Eyup

    Thanks for the response. What I ended up doing was to handle the checkbox change event and then add/remove the DataKey to a List<string> and then at the end remove those from my filtered grid.

    Bit of a work around, but working 100% now.

    Thank you.
  9. Clara
    Clara avatar
    14 posts
    Member since:
    Oct 2016

    Posted 05 Nov 2018 in reply to Stefan Link to this post

    Hello,

    I have an issue in regards to the topic specified above.

    I have a radgrid in a winform where data is populated for the user. Then, when the data is populated, Users have to apply some filters ,depend on the request, and submit  process via clicking a button on the screen.

    The problem is that I want to get the current data on the grid (after applying the filters) but I keep struggleing with that. Please it is quite urgent. Can you help me? Let me show you the two options that I am doing (none of them are working for me)

    1st Option

    System.Data.DataTable dt_filtered = new DataTable();

    string filterexpression = string.Empty;

    filterexpression = radGridView1.MasterTemplate.FilterDescriptors[0].Expression;

    dt_filtered = dtGrid.AsEnumerable().AsQueryable().Where(filterexpression).CopyToDataTable();

    This option is giving me an error "LinqDataSource, Repeaters and "Expression Expected" exception".

     

    The second option was to use this.radGridView1.ChildRows but since this is returning a RowInfo, we do not know how to add those rows into a datatable.

     

    Pleasee heelp :(

     

    Thanks so much in advance!

     

  10. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 06 Nov 2018 Link to this post

    Hello, Clara, 
      
    Note that RadGridView exposes two collections that contain data rows:
    - Rows - contains all data rows that belong to RadGridView. Data operations such as grouping, sorting, filtering, etc. do not change the content of the collection or the order in which the row objects exist in the collection.
    - ChildRows - returns the data rows that are currently represented by RadGridView in the order in which they appear. The collection is modified every time a data operation (grouping, sorting, filtering) occurs. 

    You can iterate the ChildRows collection where each data row has a DataBoundItem property storing the source record of the associated collection as DataSource. Thus, you can fill a DataTable with the filtered data. 
     
    Off topic, note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  11. Betsy Lipschutz
    Betsy Lipschutz avatar
    4 posts
    Member since:
    Jul 2019

    Posted 25 May in reply to Dess | Tech Support Engineer, Sr. Link to this post

    "Child Rows" does not work if filtered data spans across multiple pages.

    It accounts records only from current page.

    Any solution for looping through all filtered records (including all pages)?

  12. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 25 May Link to this post

    Hi, Betsy,

    Please refer to the following KB article which I believe would be suitable for your scenario: https://docs.telerik.com/devtools/winforms/knowledge-base/get-all-filtered-rows-in-gridview-with-paging 

    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  13. Betsy Lipschutz
    Betsy Lipschutz avatar
    4 posts
    Member since:
    Jul 2019

    Posted 28 May in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks Dess

    It worked perfectly as required.

Back to Top