This is a migrated thread and some comments may be shown as answers.
Set value of ComboDescriptor for predefined filter
1 Answer 16 Views
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 24 Aug 2018, 04:59 PM

     I have a RadDataFilter linked to a RadDataGrid which is functioning as desired.  I have a RadChartView (Bar Chart) that is a summary of what is being displayed in the Grid.  When I click a bar in the bar chart, I am populating the filter with a string that will filter the grid on only the rows that are related to the Bar.

Everything in this scenario is working, in that I get the filter looking correctly, based on the bar I clicked and the grid properly filtering.  The issue is that the filter item is DataFilterComboDescriptorItem and it is not displaying the correct value in the dropdown for the item specified.  It is basically displaying the last value ever selected, regardless of if I clear the filter.  

How is the value of a DataFilterComboDescriptorItem set when a RadDataFilter.Expression is manually assigned which affects that item?

Thoughts?

Here is my code:

Building the Filter Nodes Dynamically:

Private Sub SetupFilter(ByRef FilterDT As DataTable)
 
        Dim sFilterHold As String = RadDataFilter1.Expression
        RadDataFilter1.Descriptors.Clear()
        Me.RadDataFilter1.DataSource = FilterDT
        RadDataFilter1.Descriptors.Clear()
 
        Dim sSQL As String = "SELECT FilteredColumnName,DisplayText,FilterDataType FROM dbo.MAPPS_GridFilterDetail WHERE FilterHeaderId = 1 AND ActiveYN = 1"
        Dim dr As SqlDataReader = CLIB_MAPPS.Configuration.DBAccess.getSQLDataReader(sSQL)
        While dr.Read
            If dr("FilterDataType") = "DropDownList" Then
                Dim ddItem As New DataFilterComboDescriptorItem()
                ddItem.DescriptorName = dr("FilteredColumnName")
                ddItem.DescriptorType = GetType(Integer)
                ddItem.DataSource = GetTable(dr("FilteredColumnName"))
                ddItem.ValueMember = "ID"
                ddItem.DisplayMember = "Description"
                ddItem.DropDownStyle = RadDropDownStyle.DropDown
                ddItem.AutoCompleteMode = AutoCompleteMode.Suggest
                ddItem.FilterOperators.Clear()
                ddItem.FilterOperators.Add(Telerik.WinControls.Data.FilterOperator.IsEqualTo)
                ddItem.FilterOperators.Add(Telerik.WinControls.Data.FilterOperator.IsNotEqualTo)
                ddItem.Tag = dr("DisplayText")
                RadDataFilter1.Descriptors.Add(ddItem)
            Else
                Dim DescItem As New DataFilterDescriptorItem()
                DescItem.DescriptorName = dr("FilteredColumnName")
                DescItem.DescriptorType = Type.GetType(dr("FilterDataType"))
                DescItem.Tag = dr("DisplayText")
                RadDataFilter1.Descriptors.Add(DescItem)
            End If
        End While
        dr.Close()
        dr = Nothing
 
        Me.RadDataFilter1.Expression = sFilterHold
        If Me.RadDataFilter1.Expression.Length > 0 Then
            Me.ApplyFilter()
        End If
    End Sub
 
    Private Function GetTable(ByVal sColName As String) As DataTable
        Dim sSQL As String = ""
        Select Case sColName
            Case "Priority_Id"
                sSQL = "SELECT Priority_Id ID,convert(varchar(10), Priority_Id) + ' - ' + Priority_Description Description FROM Priority ORDER BY Priority_Id"
            Case "Category_Id"
                sSQL = "SELECT Category_Id ID, Cat_Description Description FROM Category ORDER BY Category_Id"
            Case "EA_Id"
                sSQL = "SELECT EA_Id ID, Adequecy_Desc Description FROM Education_Adequecy ORDER BY EA_Id"
            Case "Status"
                sSQL = "SELECT Status ID, Description Description FROM Deficiency_Assessment_Status_Lookup ORDER BY Status"
            Case "System_Id"
                sSQL = "SELECT System_Id ID, Systems_Name Description FROM Systems ORDER BY Systems_Order"
            Case "Unit_Id"
                sSQL = "SELECT Unit_Id ID, Unit Description FROM Unit_Lookup ORDER BY Unit"
        End Select
        Dim ds As DataSet = CLIB_MAPPS.Configuration.DBAccess.getDataSet(sSQL, "FilterTable")
 
        Return ds.Tables(0)
 
    End Function

 

Click Event from the Bar Chart to set the filter:

Private Sub radchrtRenoCostBySystem_SelectedPointChanged(sender As Object, args As ChartViewSelectedPointChangedEventArgs)
    If args.NewSelectedPoint IsNot Nothing Then
        Dim sSystemID As String = DirectCast(args.NewSelectedPoint.DataItem, System.Data.DataRowView).Row.ItemArray(0)
        Me.RadDataFilter1.Expression = "[System_Id] = " & sSystemID
        'THIS IS WHERE I WOULD WANT TO SET THE VALUE IN THE DROPDOWN TO MATCH THE sSystemID SELECTED
        ApplyFilter()
    End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 28 Aug 2018, 01:55 PM
Hello Mark,

Thank you for writing.

I am not able to reproduce the observed behavior with the latest version which is 2018.2.621, however, I can reproduce it with prior versions. The drop-down list editor in the latest release is affected by a fix of the following item: FIX. RadDropDownList - the selected index is not cleared when the SelectedValue does not exist in the data source

In case updating to the latest version is not possible, you can consider setting the DefaultValue property of the combo descriptor item. Please check my code snippet below: 
private void radButton1_Click(object sender, EventArgs e)
{
    this.radDataFilter1.Descriptors.Clear();
 
    List<int> listData = new List<int> { 1, 2, 3, 4, 5 };
 
    DataFilterComboDescriptorItem comboItem = new DataFilterComboDescriptorItem();
    comboItem.DescriptorName = "Custom 2";
    comboItem.DataSource = new List<int> { 1, 2, 3, 4, 5 };
    comboItem.FilterOperators.Clear();
    comboItem.FilterOperators.Add(Telerik.WinControls.Data.FilterOperator.IsGreaterThan);
    comboItem.FilterOperators.Add(Telerik.WinControls.Data.FilterOperator.IsLessThan);
    comboItem.FilterOperators.Add(Telerik.WinControls.Data.FilterOperator.IsEqualTo);
    comboItem.DefaultValue = null;
    this.radDataFilter1.Descriptors.Add(comboItem);
}

I hope this will help. Let me know if you need further assistance.

Regards,
Hristo
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.
Asked by
Mark
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or