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

Conditional Format on Column Filter

4 Answers 107 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Clarian Villamayor
Top achievements
Rank 1
Clarian Villamayor asked on 13 Aug 2012, 12:00 PM
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

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 14 Aug 2012, 08:14 AM
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.

0
Clarian Villamayor
Top achievements
Rank 1
answered on 27 Sep 2012, 12:21 PM
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
0
Dimitrina
Telerik team
answered on 28 Sep 2012, 08:38 AM
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.

0
Shawn
Top achievements
Rank 1
answered on 15 Nov 2012, 09:40 PM
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";
Tags
GridView
Asked by
Clarian Villamayor
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Clarian Villamayor
Top achievements
Rank 1
Shawn
Top achievements
Rank 1
Share this question
or