This is a migrated thread and some comments may be shown as answers.

[Solved] Custom sort/filter function

2 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Spam Basura
Top achievements
Rank 1
Spam Basura asked on 22 Dec 2009, 01:17 PM
Hi all, i have an issue related with the automatic sort/filter capabilities of the RadGridView control.

The problem is that i'm using a very complex type as the ItemSource of the grid... basically is a generic representation of a table as Dictionay<int, Dictionary<string, object>>, where "int" represents the index of the row, and then a dictionary to save the values of the columns indexed by the column name.

The data displays correctly using a conversor, but fails when ordering or filtering.

The question: Is possible to define a custom sort/filter function as a Conversor in the RadGridView, to resolve this?.

Any suggestion?.

Thx.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 22 Dec 2009, 02:19 PM
Hello Spam Basura,

You can implement custom sorting by attaching to the Sorting event like demonstrated in this online example.

For custom filtering, you can create your own Custom Filtering Control as demonstrated in this online example. For a step-by-step tutorial please read my blog post Custom Filtering with RadGridView for Silverlight.

The main point for both is that you should be creating, adding and removing the appropriate descriptors to the FilterDescriptors and SortDescriptors collections. It is up to you to what they will contain.

I hope this helps.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Spam Basura
Top achievements
Rank 1
answered on 22 Dec 2009, 03:50 PM
Thank you Mr. Telerik, I have especified the Sorting event as follows and is working correctly:

        /// <summary>
        /// Manejador de la ordenación del grid de datos
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void f_rgv_GridDatos_Sorting(object sender, Telerik.Windows.Controls.GridViewSortingEventArgs e)
        {
            //Evitar la ordenación automática
            e.Cancel = true;

            //Definir la ordenación para la propiedad especificada
            using (f_rgv_GridDatos.DeferRefresh())
            {
                f_rgv_GridDatos.SortDescriptors.Clear();

                if (e.NewSortingState != Telerik.Windows.Controls.SortingState.None)
                {
                    //Definir la ordenación para el campo especificado (cada valor es del tipo KeyPairValue)
                    f_rgv_GridDatos.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor
                    {
                        Member = "Value['" + e.SortPropertyName + "']",
                        SortDirection = (e.NewSortingState == Telerik.Windows.Controls.SortingState.Ascending) ? System.ComponentModel.ListSortDirection.Ascending : System.ComponentModel.ListSortDirection.Descending
                    });
                }
            }
        }

Hope this helps other people
Tags
GridView
Asked by
Spam Basura
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Spam Basura
Top achievements
Rank 1
Share this question
or