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

RadGrid with template filter does not work correctly.

3 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TomShelby
Top achievements
Rank 1
TomShelby asked on 23 May 2019, 05:50 AM

Hello, I have a database with a numeric field (State) that has the following values: 0, 1, 2, 3 and 4. In the Template Filter I have associated a combobox with the text associated with each value.

I want to see the text both in the field and in the filter, but I do not get it. You can help me see what I have wrong. Thank you

<telerik:GridTemplateColumn DataField="Estado" HeaderText="Estado" UniqueName="Estado" DataType ="System.String"    SortExpression="Estado" GroupByExpression="Estado Group by Estado" ReadOnly "true"><br>                               
<ItemTemplate><br>                               
<asp:Label runat="server"<br>                                   
ID="Estado" <br>  Text= '<%# DataBinder.Eval(Container.DataItem, "Estado") %>'><br>                                </asp:Label> <br>
</ItemTemplate><br>
<FilterTemplate><br>                                   
<telerik:RadComboBox RenderMode="Lightweight" ID="RcEstado" Width="90px" <br>                                        SelectedValue='<%# CType(Container, GridItem).OwnerTableView.GetColumn("Estado").CurrentFilterValue %>'       runat="server" OnClientSelectedIndexChanged="Estado_SelectedIndexChanged"><br>                                        <Items><br>
<telerik:RadComboBoxItem Text="Todo" Value="" Selected="True" /> <br>                                            <telerik:RadComboBoxItem Text="Sin incidencia" Value="0" /><br>                                            <telerik:RadComboBoxItem Text="El código de farmacia no existe en la base datos."Value="1"/><br>
<telerik:RadComboBoxItem Text="La clave de acceso no coincide" Value="2" />                                    <telerik:RadComboBoxItem Text="No se ha encontrado ninguna clave de acceso que no esté caducada." Value="3"
<telerik:RadComboBoxItem Text="La clave está caducada." Value="4" /><br>                                        </Items>
</telerik:RadComboBox><br>                                   
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"><br>                                       
<script type="text/javascript">
function Estado_SelectedIndexChanged(sender, args) {<br>                                           
var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
tableView.filter("Estado", args.get_item().get_value(), "EqualTo");<br>                                                                                  </script><br>                                   
</telerik:RadScriptBlock><br>                               
</FilterTemplate><br>                           
<EditItemTemplate><br>                           
<telerik:RadDropDownList ID="DropDownList4" runat="server" AutoPostBack="true" DataValueField="Activa" SelectedValue='<%#Bind("PingSrv") %>' OnSelectedIndexChanged="DropDownList4_selectedindexchanged"><br>                                <Items><br>
<telerik:DropDownListItem Text="El código de farmacia no existe en la base de datos." Value="1"
<telerik:DropDownListItem Text="La clave de acceso no coincide" Value="2" /><br>                                    <telerik:DropDownListItem Text="No se ha encontrado ninguna clave de acceso que no esté caducada." Value="3"
<telerik:DropDownListItem Text="La clave está caducada." Value="4" /><br>                            
</Items><br>
</telerik:RadDropDownList><br>                       
</EditItemTemplate><br>                         </telerik:GridTemplateColumn>

3 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 27 May 2019, 03:45 PM
Hi Tom,

I've created a sample page with the GridTemplateColumn you've shared and the filtering seems to work. Here is a short video of the test restults: RadGrid ComboBox Filtering. Also, I have attached the sample page to my response. You can check it out and test it yourself.

Could you please describe it in more details or steps about what would you like to achieve and is not working?

I look forward to hearing from you.

Kind regards,
Attila Antal
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.
0
TomShelby
Top achievements
Rank 1
answered on 28 May 2019, 06:01 AM

Hi Attila, Thanks for your answer.

In RADCOMBOBOX I want the literal to appear (TEXT not VALUE).

And let that literal be the one shown in each row of the grid for that column.

And that also serves for the filter.

In your example, this is with the VALUE of the RADCOMBOBOX.

Grateful for the help

0
Attila Antal
Telerik team
answered on 30 May 2019, 03:27 PM
Hi Tom,

In order to display the same text in the grid column as appeared in ComboBox, the DataSource bound to RadGrid must also contain the same Text associated with its ID.



Here are several options that need to be adjusted:
  • Set the DataField and UniqueID properties of the Template column to "EstadoID".
  • Label in the ItemTemplate must Evaluate the "Estado" field from the DataSource. This is the Text that will be displayed.
  • ComboBox in the FilterTemplate, will have its selected value based on the "EstadoID" column FilterValue.
  • Changing the ComboBox item, will also apply the filtering on the "EstadoID" column.

I have marked all the fields with yellow in the code snippet below:

<telerik:GridTemplateColumn DataField="EstadoID" HeaderText="Estado" UniqueName="EstadoID" DataType="System.String" SortExpression="EstadoID" GroupByExpression="EstadoID Group by EstadoID" ReadOnly="true">
    <FilterTemplate>
        <telerik:RadComboBox RenderMode="Lightweight" ID="RcEstado" Width="200px" SelectedValue='<%# CType(Container, GridItem).OwnerTableView.GetColumn("EstadoID").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="Estado_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem Text="Todo" Value="" Selected="True" />
                <telerik:RadComboBoxItem Text="Sin incidencia" Value="0" />
                <telerik:RadComboBoxItem Text="El código de farmacia no existe en la base datos." Value="1" />
                <telerik:RadComboBoxItem Text="La clave de acceso no coincide" Value="2" />
                <telerik:RadComboBoxItem Text="No se ha encontrado ninguna clave de acceso que no esté caducada." Value="3" />
                <telerik:RadComboBoxItem Text="La clave está caducada." Value="4" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function Estado_SelectedIndexChanged(sender, args) {
                    var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");
                    tableView.filter("EstadoID", args.get_item().get_value(), "EqualTo");
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
 
    <ItemTemplate>
        <asp:Label runat="server" ID="Estado" Text='<%# DataBinder.Eval(Container.DataItem, "Estado") %>'></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>

I have adjusted the sample page to resemble the above scenario. I hope this will help resolve the issue.

Kind regards,
Attila Antal
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.
Tags
Grid
Asked by
TomShelby
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
TomShelby
Top achievements
Rank 1
Share this question
or