DateTime Client Filtering

2 posts, 0 answers
  1. Clément
    Clément avatar
    1 posts
    Member since:
    Jul 2014

    Posted 16 Jul 2015 Link to this post

    Hi,

    I have some problems to filtering my grid with a FilterTemplate, the client-side event is fired but the method tableView.filter doesn't work properly. The filter return no records.

    Here is my .ascx :

    <telerik:RadGrid ID="RadGridPoleResult" runat="server" CssClass="gridPoleResult"
        AllowPaging="true" AllowSorting="true"  PageSize="100"
        AllowFilteringByColumn="True" Skin="MetroTouch" ViewStateMode="Disabled" ClientDataSourceID="RadClientDataSource1">
        <MasterTableView DataKeyNames="Recid_reporting" ClientDataKeyNames="Recid_reporting" AutoGenerateColumns="False" AllowFilteringByColumn="true" AllowSorting="true">
            <PagerStyle Mode="NumericPages" ShowPagerText="false"/>  
            <Columns>
                    <telerik:GridBoundColumn  HeaderText="ID Reporting" HeaderStyle-HorizontalAlign="Center"
                    DataField="Recid_reporting" UniqueName="col_ID" Visible="true" ShowFilterIcon="false" FilterControlWidth="60px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Date"  HeaderStyle-HorizontalAlign="Center" FilterControlWidth="150px"
                    DataField="Date" UniqueName="col_Date" DataFormatString="{0:D}" DataType="System.DateTime">
                        <FilterTemplate>
                                From
                            <telerik:RadDatePicker ID="FromOrderDatePicker" runat="server" Width="140px" ClientEvents-OnDateSelected="FromDateSelected"
                                MinDate="01-01-2010" SelectedDate="01-01-2010"/>
                                to
                            <telerik:RadDatePicker ID="ToOrderDatePicker" runat="server" Width="140px" ClientEvents-OnDateSelected="ToDateSelected"
                                MinDate="01-01-2010"  SelectedDate="01-01-2010"/>
                                <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                                    <script type="text/javascript">
                                        function FromDateSelected(sender, args) {
                                            var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                            var ToPicker = $find('<%# ((GridItem)Container).FindControl("ToOrderDatePicker").ClientID %>');

                                            var fromDate = FormatSelectedDate(sender);
                                            var toDate = FormatSelectedDate(ToPicker);

                                            tableView.filter("col_Date", fromDate + " " + toDate, "Between");

                                        }
                                        function ToDateSelected(sender, args) {
                                            var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                            var FromPicker = $find('<%# ((GridItem)Container).FindControl("FromOrderDatePicker").ClientID %>');

                                            var fromDate = FormatSelectedDate(FromPicker);
                                            var toDate = FormatSelectedDate(sender);

                                            tableView.filter("col_Date", fromDate + " " + toDate, "Between");
                                        }
                                        function FormatSelectedDate(picker) {
                                            var date = picker.get_selectedDate();
                                            var dateInput = picker.get_dateInput();
                                            var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());

                                            return formattedDate;
                                        }
                                    </script>
                                </telerik:RadScriptBlock>
                            </FilterTemplate>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Salarié"  HeaderStyle-HorizontalAlign="Center"
                    DataField="Employee" UniqueName="col_Employee"  ShowFilterIcon="false" FilterControlWidth="80px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Gamme"  HeaderStyle-HorizontalAlign="Center"
                    DataField="Gamme" UniqueName="col_Gamme"  ShowFilterIcon="false" FilterControlWidth="120px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Tache"     HeaderStyle-HorizontalAlign="Center"
                    DataField="Task" UniqueName="col_Task"  ShowFilterIcon="false" FilterControlWidth="120px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Quantités déclarées"  HeaderStyle-HorizontalAlign="Center"
                    DataField="DeclaredQty" UniqueName="col_DeclaredQty"  ShowFilterIcon="false" FilterControlWidth="50px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Temps déclaré"     HeaderStyle-HorizontalAlign="Center"
                    DataField="DeclaredTime" UniqueName="col_DeclaredTime"  ShowFilterIcon="false" FilterControlWidth="50px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Temps passé unitaire"  HeaderStyle-HorizontalAlign="Center"
                    DataField="SpentTimeUnit" UniqueName="col_SpentTimeUnit"  ShowFilterIcon="false" FilterControlWidth="50px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Objectif Temps Unitaire"  HeaderStyle-HorizontalAlign="Center"
                    DataField="ObjectiveTimeUnit" UniqueName="col_ObjectiveTimeUnit"  ShowFilterIcon="false" FilterControlWidth="50px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="PPJ"     HeaderStyle-HorizontalAlign="Center"
                    DataField="PPJ" UniqueName="col_PPJ"  ShowFilterIcon="false" FilterControlWidth="50px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Observation"  HeaderStyle-HorizontalAlign="Center"
                    DataField="Observation" UniqueName="col_Observation"  ShowFilterIcon="false" FilterControlWidth="60px" FilterDelay="200">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Cadence"  HeaderStyle-HorizontalAlign="Center"
                    DataField="Cadence" UniqueName="col_Cadence" Display="false"  ShowFilterIcon="false" FilterControlWidth="120px" FilterDelay="200">
                    </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings>
                <ClientEvents OnRowDataBound="OnRowDataBound" />
        </ClientSettings>
    </telerik:RadGrid>

    <telerik:RadClientDataSource runat="server" ID="RadClientDataSource1">
            <DataSource>
                <WebServiceDataSourceSettings>
                    <Select Url="/DesktopModules/Itancia SuiviProd/WebServices/API/Reporting/GetAllPoleReporting" RequestType="Get" />
                </WebServiceDataSourceSettings>
            </DataSource>
            <Schema>
                <Model ID="Recid_reporting">
                    <telerik:ClientDataSourceModelField FieldName="Recid_reporting" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Date" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Employee" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Gamme" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Task" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="DeclaredQty" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Cadence" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="DeclaredTime" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="PPJ" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Observation" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="ObjectiveTimeUnit" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="SpentTimeUnit" DataType="String" />
                </Model>
            </Schema>
    </telerik:RadClientDataSource>

     

    And my .js :

    function OnRowDataBound(sender, args) {
        var dataItem = args.get_dataItem();

        if (dataItem.PPJ > 95) {
            args.get_item().get_cell("col_PPJ").style.background = "#D2FFD2";
        }
        else {
            args.get_item().get_cell("col_PPJ").style.background = "#FFD7FF";
        }

        if (dataItem.PPJ <= 0) {
            args.get_item().get_cell("col_PPJ").style.background = "LightGray";
        }

        args.get_item().get_cell("col_Date").innerHTML = moment(dataItem.Date).format("DD/MM/YYYY").toString();
    }​

     

    For information, my version of Telerik.Web.UI is 2014.3.1209.40 and the used date format is dd/mm/yyyy.

     

    Do you have an idea about this problem ?

     

     Thank you,

    Clément

  2. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 21 Jul 2015 Link to this post

    Hello Clément,

    I assume the cause for this issue is that the value from he DateInput does not match the one from your datasource. Could you please check out what is the formated value of fromDate and toDate and what are the values that comes from your datasource?  Additionally for test purpose you can try adding a filter expression in advance and check whether some values are returned. more information about applying a FilterExpressions can be found in the following help article.

    Regards,
    Kostadin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top