GridView bound to indexer

5 posts, 0 answers
  1. Przemysław
    Przemysław avatar
    18 posts
    Member since:
    Apr 2014

    Posted 06 Nov 2014 Link to this post

    Hello,
    I'm creating datagrid with dynamically created columns. The ViewModel looks like:
    public string this[Guid column]
     {     
        get { ....}
        
    set { ... }
    }

    And I create columns this way:
    GridViewDataColumn col = new GridViewDataColumn();<br>
    col.Header = c.Column.Name;<br>
    col.DataMemberBinding = new Binding(String.Format("[{0}]", c.Column.Id)) { FallbackValue = null };
    col.ColumnGroupName = g.Header;
     
    this.Columns.Add(col);


    I had some problems - sorting (fixed by custom ICollectionView link) but now I have issue with filtering. When i try to filter, grid becomes empty. And also I cannot see list with checkboxes to select desired values (like for normal column bound to string property).

    Is there anything I can do with that? ICollectionView  has filter property, but it's not used in Telerik Datagrid (?).
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Nov 2014 Link to this post

    Hello,

    Would you please try specifying a proper DataType for each of the columns bound the indexer's values. That way the sorting and filtering should work fine.

    Let me know if this helps.


    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Przemysław
    Przemysław avatar
    18 posts
    Member since:
    Apr 2014

    Posted 12 Nov 2014 in reply to Dimitrina Link to this post

    Hi,

    Nope, that doesn't help - see screenshot.

    I'm creating columns this way (currently all of them are strings):
    GridViewDataColumn col = new GridViewDataColumn();
    col.Header = c.Column.Name;
    col.DataMemberBinding = new Binding(String.Format("[{0}]", c.Column.Id)) { IsAsync = true, FallbackValue = null };
    col.ColumnGroupName = g.Header;
    col.FilterMemberPath = "";
     
    switch (c.Column.Type)
    {
        case ComplinkTableColumnType.Double:
            col.DataType = typeof(double);
            col.FilterMemberType = typeof(double);
            break;
        case ComplinkTableColumnType.Integer:
            col.DataType = typeof(int);
            col.FilterMemberType = typeof(int);
            break;
        case ComplinkTableColumnType.Bool:
            col.DataType = typeof(bool);
            col.FilterMemberType = typeof(bool);
            break;
        default:
            col.DataType = typeof(string);
            col.FilterMemberType = typeof(string);
            break;
    }
     
    Columns.Add(col);

    And as you see, filters are for strings but listbox with values to select is empty.

    Kind Regards,
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Nov 2014 Link to this post

    Hi,

    I am sorry to hear my suggestion did not help.

    I will try to elaborate more on how the filtering actually works. It is a data operations which means it is done by building and executing a LINQ query appending proper Where clause over the source collection. 
    For example:
    var result = collection.Where(item => item.Property == "Something");

    The reason for not working should be that our data engine cannot build a valid LINQ query based on the specified binding. 
    So, if you can build such a LINQ query appending Where clause based on the DataMemberBinding set for a column, then RadGridView should also be able to filter the respective column. Otherwise, this will not be possible.

    If you can build a valid LINQ query and RadGridView still does not show filtering options, then may I ask you to isolate the case in a demo project which I can check locally? You can open a new support ticket and attach it there.


    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Przemysław
    Przemysław avatar
    18 posts
    Member since:
    Apr 2014

    Posted 20 Nov 2014 in reply to Dimitrina Link to this post

    Hi,

    I've managed to do it. Just by creating a bunch of generic 'bridge' objects for each of data types.
    If indexer is returing strongly typed data (not just object) it will work.
    So for T columns I'm creating proxy object with
    public T this[string columnId] {get (...)}
    And bounding column to it to ViewModel.TProxy["guid"]

    Cheers,
Back to Top