Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Criteria with date field defaults to todays date

    SmartClient_SNAPSHOT_v90d_2013-05-20

    We have implemented a way for users to persist the grid state to a database so when they log into the system their look and feel is the same. We save the filter criteria as well. This works except for date fields. The criteria is saved to the database with the correct date value, although it is a string. However, when the filter is applied using setCriteria, the date displays as todays date. I think this is due to the fact the the advanced criteria is saving the date as a string.

    The type is date, as it is represented by a Java Date object.

    Repro Steps:
    1. Load the test case
    2. Open the filter dialog with the command dialog.show()
    3. Execute the following code (simulating my entore save and load implementation):
    Code:
    dialog.show();
    var filterState = { 
       _constructor:"AdvancedCriteria",
       operator:"and",         
       criteria:[
    		{ 	fieldName:"lastInspectionDate",
    			operator:"greaterThan", 
    			value:"2013-03-31" 
    		}        
    	]    
    }
    filter.setCriteria(filterState);
    I would expect that since LastInspectionDate is a date field, the filter should parse the value and set the filter correctly. However, observe that the date is 5/20/2013 (today).


    Test case:
    Code:
    <!DOCTYPE html>
    
    <html>
    <head>
        <title >SNTQ-1791</title>
    	
       	<script type="text/javascript" >
    		var isomorphicDir="http://localhost:8080/isomorphic/";
    		
    		var data = [
    			{inspectorID:12345, inspections:206,observations:913,lastInspectionDate:new Date(2012, 8, 13),index:52.6, inspectionType: {id:123, name:"type1"}},
    			{inspectorID:67890, inspections:66,observations:0,lastInspectionDate:new Date(2013, 2,2),index:75.3, inspectionType: {id:123, name:"type1"}},
    			{inspectorID:88776, inspections:66,observations:67,lastInspectionDate:new Date(2013,2,3),index:75.3, inspectionType: {id:123, name:"type1"}},
    			{inspectorID:44556, inspections:206,observations:0,lastInspectionDate:new Date(2012,8,31),index:52.6, inspectionType: {id:123, name:"type1"}}
    		];
    </script>
    	
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Core.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Foundation.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Containers.js"></script>
      <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Grids.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Forms.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_DataBinding.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Drawing.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_PluginBridges.js"></script> 
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Charts.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Tools.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/skins/EnterpriseBlue/load_skin.js"></script>
    	
    </head>
    <body>
    
    	<br><br>
    	<script>
    	
    			isc.DataSource.create({
    				ID: "ds",
    				fields: [
    					{name:"inspectorID", title:"Inspector ID", type:"integer" },
    					{name:"inspections", type:"integer", title:"# Inspections"},
    					{name:"static", type:"string", title:"Static Field"},
    					{name:"observations", title:"# Observations"},
    					{name:"lastInspectionDate", type:"date", title:"Last Inspection"}
    				],
    				cacheData:data,
    				clientOnly: true
    			});
    			
    			var gridObject = isc.ListGrid.create({
    				dataSource: ds,
    				dataFetchMode : "local",
    				autoFetchData: true,
    				clientOnly: true,
    				width : "100%",
    				align : "center",
    				autoFitData : "vertical",
    				autoFitMaxHeight : 400,
    				alternateRecordStyles : true,
    				canAddFormulaFields : true,
    				canAddSummaryFields : true,
    				canGroupBy : true,
    				canReorderFields : true,
    				showGroupSummary : true,
    				groupByMaxRecords : 5
    			});	
    			
    			var filter = isc.FilterBuilder.create({
    				dataSource : ds,
    				topOperatorAppearance : "radio",
    				allowEmpty : true,
    				height : 10
    			});
    			
    			var dialog = isc.Window.create({
    				width : 600,
    				height : 350,
    				title : "Filter Grid",
    				canDragReposition : true,
    				canDragResize : true,
    				padding : 10,
    				autoCenter : true,
    				autoDraw : false,
    				items : [ filter, isc.LayoutSpacer.create({
    					height : 10
    				}), isc.HLayout.create({
    					membersMargin : 25,
    					defaultLayoutAlign : "center",
    					align : "center",
    					width : "100%",
    					height : 10,
    					members : [ isc.IButton.create({
    						ID : "filterButton",
    						title : "Filter",
    						click : function() {
    							gridObject.filterData(filter.getCriteria());
    						}
    					}), isc.IButton.create({
    						ID : "clearFilterButton",
    						title : "Clear Filter",
    						click : function() {
    							_filterObject.clearCriteria();
    							gridObject.filterData(filter.getCriteria());
    						}
    					}) ]
    				}) ]
    			});
    				
    	</script>
    	<br><br>
    
    </body>
    
    </html>

    #2
    The criteria does need to be specified as an actual date.

    If you use our JSON.encode() function to store the criteria, we provide a mode that round-trips dates across encode/decode.

    Comment


      #3
      Thanks, that did the trick!

      Comment

      Working...
      X