Conditional Format on Column Filter

5 posts, 0 answers
  1. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 13 Aug 2012 Link to this post

    Hi Telerik,

    I have a grid that displays a decimal? type property called Quantity 
    which is formatted to string based on another boolean property AllowDecimal.

    I use an extended String property FormattedQuantity with the ff logic.

     if (AllowDecimal)
          return string.Format("{0:0.000}", value);
    else
          return string.Format("{0:0}", value); 

    I also use a Textbox in the ColumnCellTemplate to display the converted string. 

    But to enable number/decimal filtering (not string filtering) such as
    • "Is not equal to"  
    • "Is less than"
    • "Is greater than" 
    • etc.
    I still use the actual decimal property for the column data binding 
    ...
    <telerik:GridViewDataColumn Header="Qty" DataMemberBinding="{Binding Quantity}"/>
    <telerik:GridViewDataColumn.CellTemplate>
         <DataTemplate>
              <TextBlock Text="{Binding FormattedQuantity}" TextAlignment="Right"/>
         </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
    <telerik:GridViewDataColumn >
    ...

    e.g. Quantity Column displays
    • 3.432 
    • 6


    And when I try to filter, the numbers displayed are not formatted (see attached image)
    e.g.
    • 3.432000
    • 6.000000


    Question:
    How is it possible for the filter popup to display the formatted value based on a condition while binding the decimal property?
    e.g.
    • 3.432 
    • 6 


    Thanks
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Aug 2012 Link to this post

    Hi,

    Generally to format the distinct values the same way as you format the values shown in the GridView, you could use a Converter for the Binding to the DataMemberBinding of the column. In your case you would like to decide what format should be applied based on another property (AllowDecimal). The problem is that in the converter you do not know what the value for this property is. If you find a way to access this value, then this will for you. Otherwise applying the conditional format would not be possible. 

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Clarian Villamayor
    Clarian Villamayor avatar
    13 posts
    Member since:
    Jun 2010

    Posted 27 Sep 2012 Link to this post

    Hi,

    Yes, I have access to the property via a related object Item.
    e.g. line.Item.AllowDecimal
    
    .. ItemSource={Binding Lines} />
    
    <telerik:GridViewDataColumn Header="Qty" 
    
    DataMemberBinding="{Binding Quantity, 
    Converter={StaticResource formattedDecimalConverter},  ConverterParameter={Binding Item.AllowDecimal}}" />

    But I am getting an error:
    "Operation is not valid due to the current state of the object."

    --- OR even when I use an extended Property "AllowDecimal", error still persists: --- 
    public partial class Line {
      public bool AllowDecimal
      {
        get  {  return this.Item != null && this.Item.UnitOfMeasure != null && this.Item.UnitOfMeasure.AllowDecimal; }
      }
    }
    that is binded to a converter Parameter:
    
    <telerik:GridViewDataColumn Header="Qty" 
    DataMemberBinding="{Binding Quantity, 
    Converter={StaticResource formattedDecimalByUoMConverter}, 
    ConverterParameter={Binding AllowDecimal}}" />


    How can I make it work?


    Thanks
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Sep 2012 Link to this post

    Hello,

     I am afraid that you cannot pass the data item as a parameter. 

    Greetings,
    Didie
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  6. Shawn
    Shawn avatar
    10 posts
    Member since:
    Mar 2011

    Posted 15 Nov 2012 Link to this post

    You can make the value the column binds to a complex type. So, make Quantity a complex type with a "StoredValue" as a double and a "DisplayValue" as a string. Then you can use the FilterMemberPath:

    column.FilterMemberPath = "Quantity.DisplayValue";
Back to Top
DevCraft banner