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

[Solved] Filter options not showing up when binding a datetime column

2 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chamara
Top achievements
Rank 1
Chamara asked on 11 Jul 2013, 02:04 AM
I'm trying to bind date column to RadGrid with auto generated columns. binding works fine but the filter options (contains, equal,..) does not showing up when i click on the filter icon, it just cause a post back. How ever if i bind the date column as a string then it's starts working. whats the issue here?

 <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

        <script type="text/javascript">
        

            function doFilter(sender, eventArgs) {
                if (eventArgs.keyCode == 13) {
                    eventArgs.cancelBubble = true;
                    eventArgs.returnValue = false;
                    if (eventArgs.stopPropagation) {
                        eventArgs.stopPropagation();
                        eventArgs.preventDefault();
                    }
                    var masterTableView = $find("<%= gridSearchL3.ClientID %>").get_masterTableView();
                    var index = sender.parentNode.cellIndex; //index of the current column 
                    var columns = masterTableView.get_columns();
                    var uniqueName = columns[index].get_uniqueName();
                    masterTableView.filter(uniqueName, sender.value, Telerik.Web.UI.GridFilterFunction.Contains);
                }
            }

            
        var columnUniquName = ""; 

            function removeCssClass(className, element) {
                element.className = element.className.replace(className, "").replace(/^\s+/, '').replace(/\s+$/, '');
            }

            function addCssClass(className, element) {
                if (element.className.indexOf(className) < 0) {
                    element.className = element.className + " " + className;
                }
            }
            function onRowClick(sender, eventArgs) {
                var radGrid = sender;
                var index = eventArgs.get_itemIndexHierarchical();
                var dataItem = radGrid.get_masterTableView().get_dataItems()[index];
                var row = dataItem.get_element();
                var checkBox = row.children[0].children[0];
                if (!checkBox.checked) {
                    checkBox.checked = true;
                    addCssClass("rgSelectedRow", row);
                }
                else {
                    checkBox.checked = false;
                    removeCssClass("rgSelectedRow", row);
                }

                CheckHeaderCheckBoxIfNeeded(radGrid);
            }

            function changeAllowPaging() {
                var grid = $find("<%= gridSearchL3.ClientID %>");
                var pagerRow = grid.get_masterTableView().get_element().tFoot;
                pagerRow.style.display = "none";
                grid.MasterTableView.set_pageSize(grid.MasterTableView.PageSize * grid.MasterTableView.PageCount)
                return false;

            } 

            function CheckHeaderCheckBoxIfNeeded(radGrid) {
               
                var checkHeaderCheckBox = true;
                var dataItems = radGrid.get_masterTableView().get_dataItems();
              
                for (var i = 0; i < dataItems.length; i++) {
                    var dataItem = dataItems[i];
                    var row = dataItem.get_element();
                    var ckeckBox = row.children[0].children[0];
                    if (!ckeckBox.checked) {
                        checkHeaderCheckBox = false;
                    }
                }

                SelectCheckBox(checkHeaderCheckBox);
            }

            function setSelectedAfterPostback(rowIDs, rowCount) {
                var arrRowIDs = rowIDs.split(",");
                for (var i = 0; i < arrRowIDs.length - 1; i++) {
                    var row = document.getElementById(arrRowIDs[i]);
                    var checkBox = row.children[0].children[0];
                    checkBox.checked = true;
                    addCssClass("rgSelectedRow", row);
                }
                if (rowCount == arrRowIDs.length - 1) {
                    SelectCheckBox(true);
                }
            }

            function CheckBoxCheckedOnClient(rowID, chechBoxId) {
                var row = document.getElementById(rowID);
                var ckeckBox = document.getElementById(chechBoxId);
                if (ckeckBox.checked) {
                    addCssClass("rgSelectedRow", row);
                }
                else {
                    removeCssClass("rgSelectedRow", row);
                }
                var radGrid = $find("<%= gridSearchL3.ClientID %>");
                CheckHeaderCheckBoxIfNeeded(radGrid);
            }

            function SelectCheckBox(isChecked) {
                var checkBoxID = document.getElementById("<%= HiddenField.ClientID %>").value;
                var checkBox = document.getElementById(checkBoxID);
                checkBox.checked = isChecked;
            }

            function CheckUnCheckAll(id) {
                var sender = document.getElementById(id);
                var grid = $find("<%=gridSearchL3.ClientID %>");
                var dataItems = grid.get_masterTableView().get_dataItems();
                for (var i = 0; i < dataItems.length; i++) {
                    var dataItem = dataItems[i];
                    var row = dataItem.get_element();
                    var checkBox = row.children[0].children[0];
                    if (sender.checked) {
                        checkBox.checked = true;
                        addCssClass("rgSelectedRow", row);
                    }
                    else {
                        checkBox.checked = false;
                        removeCssClass("rgSelectedRow", row);
                    }
                }
            }

               function getColumnCliecked(cu) {  
                columnUniquName = cu;  
                
    }  

            function getPDF(docNum, rev,dochTID) {

                WebService.getFilePath(docNum, rev,dochTID, OnPDFSucceed, OnPDFFailed);
            }

            function OnPDFSucceed(result) {
                //alert(result);
                openPDF(result);
            }

            function OnPDFFailed(err) {
                alert(err);
            }

            function openPDF(file) {
                window.open("OpenPDF.aspx?File=" + file);
            }

            
        </script>

    </telerik:RadCodeBlock>

<telerik:RadGrid ID="gridSearchL3" runat="server" AllowPagg="True"  
             GridLines="None" Skin="Office2007" Height="415px" 
             OnExcelMLExportRowCreated="gridSearchL3_ExcelMLExportRowCreated" OnExcelMLExportStylesCreated="gridSearchL3_ExcelMLExportStylesCreated"
            OnGridExporting="gridSearchL3_GridExporting"  oninit="gridSearchL3_Init" OnNeedDataSource="RadGrid1_NeedDataSource"
            Font-Names="Eras Medium ITC" Font-Size="Small" PageSize="50" 
             AllowFilteringByColumn="True" onitemcreated="gridSearchL3_ItemCreated" 
            OnPageIndexChanged="gridSearchL3_PageIndexChanged"
          OnPageSizeChanged="gridSearchL3_PageSizeChanged"
             onselectedindexchanged="gridSearchL3_SelectedIndexChanged" 

             AllowSorting="True" ShowStatusBar="True" AllowPaging="True" CellSpacing="0" oncolumncreated="gridSearchL3_ColumnCreated1" 
                >
               <FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="XX-Small" />
               <GroupingSettings CaseSensitive="False" />
            <ExportSettings Excel-Format="ExcelML" ExportOnlyData="True" 
                FileName="PinC Group" IgnorePaging="True" OpenInNewWindow="True">
                <Excel Format="ExcelML" />
            </ExportSettings>
            <ClientSettings>
                <ClientEvents OnRowClick="onRowClick" OnRowSelected="RowSelected" />
                <Selecting AllowRowSelect="True" />
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                    
            </ClientSettings>
            <AlternatingItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
            <GroupHeaderItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
            <SortingSettings EnableSkinSortStyles="false" /> 
            <MasterTableView ClientDataKeyNames="Document #,Revision,hID,ID" Font-Names="Eras Medium ITC" 
                   Font-Size="X-Small">
           
                <CommandItemSettings  ExportToPdfText="Export to Pdf" />
                 
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="template">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" 
                                OnCheckedChanged="ToggleRowSelection" />
                        </ItemTemplate>
                        <HeaderTemplate>
                            <asp:CheckBox ID="CheckBoxHeader" runat="server" AutoPostBack="true" 
                                OnCheckedChanged="Header_checkedChange" />
                        </HeaderTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridButtonColumn CommandName="Select" Text="View" 
                        UniqueName="LinkColumn">
                    </telerik:GridButtonColumn>
                   </Columns>
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
                <ItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
                <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                <FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
            </MasterTableView>
            <EditItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
            <FooterStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
            <HeaderStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
            <FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
               <CommandItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
               <ActiveItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
               <ItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
               <PagerStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" 
                   HorizontalAlign="Left" Mode="NextPrevNumericAndAdvanced" />
               <SelectedItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
               <FilterMenu Font-Names="Eras Medium ITC" Font-Size="X-Small" 
                Skin="Office2007" EnableRoundedCorners="True">
               </FilterMenu>
               <HeaderContextMenu Font-Names="Eras Medium ITC" Font-Size="X-Small" 
                   Skin="Simple">
               </HeaderContextMenu>
               </telerik:RadGrid>

My SQL Query.

select distinct h.DocumentRevisionID 'ID',h.DocumentHeaderID 'hID', h.DocumentNumber 'Document #', h.DocumentTitle 'Document Title',h.Revision as 'Revision',CASE CONVERT(date,[RevisionDate],103)  WHEN '01/01/1991' Then '' else CONVERT(date,[RevisionDate],103) end as 'Rev Date'   from tblDocumentHeader h    

2 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 15 Jul 2013, 03:59 PM
Hi Chamara,

Actually the Contains filter is not expected to show for a GridDateTimeColumn. It is used for string values and should return as a result the records which filtered field contains the filter value entered from the used. However the EqualTo filter should be displayed. I tried reproducing the problem described in a sample website using the code provided but to no avail. Could you please examine the attachment and tell us what differs in your case? If you could modify it so that the problem is reproducible we should be able to pin-point what is causing it.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Chamara
Top achievements
Rank 1
answered on 16 Jul 2013, 02:12 AM
hello!

sql query was causing the problem.

select distinct h.DocumentRevisionID 'ID',h.DocumentHeaderID 'hID', h.DocumentNumber 'Document #', h.DocumentTitle 'Document Title',h.Revision as 'Revision',CASE CONVERT(date,[RevisionDate],103)  WHEN '01/01/1991' Then '' else CONVERT(date,[RevisionDate],103) end as 'Rev Date'   from tblDocumentHeader h    


radgrid causes this error when query has spaces and special characters like #,-,..

I changed the query to below.

select distinct h.DocumentRevisionID 'ID',h.DocumentHeaderID 'hID', h.DocumentNumber 'DocumentNo', h.DocumentTitle 'DocumentTitle',h.Revision as 'Revision',CASE CONVERT(date,[RevisionDate],103)  WHEN '01/01/1991' Then '' else CONVERT(date,[RevisionDate],103) end as 'RevDate'   from tblDocumentHeader h    
Tags
Grid
Asked by
Chamara
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Chamara
Top achievements
Rank 1
Share this question
or