Feature table query date issues

1157
4
02-24-2017 08:16 AM
AndréRibeiro
New Contributor II

I'm having some issues querying the feature table in ArcGis JavaScript API. I already had developed query by string and coded values with success but the date fields not, unfortenely.

Can someone help me with this issue?

This is my code to query by a string field "nud":

HTML

<input id="stringTextBox" type="text" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true, intermediateChanges:true" class="dijit-form-TextBox filterTb"

<button type="button" id="confirm">Filtrar</button>

JAVASCRIPT

var confirmar = dom.byId("confirm");
             

on(confirmar, "click", function(value){
              var userVal = dijit.byId("stringTextBox").get('value');  
              var oidFld = myFeatureLayer.objectIdField;  
              var query = new Query(); 
              lastWhere = query.where = "nud LIKE '%" +  userVal + "%'";
                
            myFeatureLayer.queryIds(query, lang.hitch(this, function(objectIds) {  
               myFeatureTable.selectedRowIds = objectIds;  
               myFeatureTable._showSelectedRecords();
               }));  
           }); 

0 Kudos
4 Replies
TomSellsted
MVP Regular Contributor

Andre,

Looking at your query, it looks like you are trying to do a wildcard selection of a date field.  Please try using a more specific selection like:

query.where = "nud = '" +  userVal + "'";

Date fields can be a bit tricky to work with as they may contain date/time values so finding an exact match would mean also have to specify a time or time range.  Something like:

query.where = "nud between '" + userVal + " 00:00' and '" + userVal + " 23:59'";

Regards,

Tom

AndréRibeiro
New Contributor II

Thank you for your time Tom!

I already did that query, but I'm having the same issue before. I have an error on console: "Unable to complete operation".

Maybe query date fields are different of query another type fields like text?

Here's my code:

HTML

<input id="data1" type="text" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true, intermediateChanges:true" class="dijit-form-TextBox filterTb" style="width: 100px;"/>
<input id="data2" type="text" data-dojo-type="dijit/form/TextBox" data-dojo-props="trim:true, intermediateChanges:true" class="dijit-form-TextBox filterTb" style="width: 100px;"/>
<button type="button" id="confirm4">Filtrar</button>

Javascript

var confirmar4 = dom.byId("confirm4");
              
on(confirmar4, "click", function(value){     
   var userVal4 = dijit.byId("data1").get('value');     
   var userVal5 = dijit.byId("data2").get('value');     
   var oidFld = myFeatureLayer.objectIdField;  
   var query = new Query();  
   query.where = "data_de_inicio between '" + userVal4 + " 00:00' and '" + userVal5 + " 23:59'"; 
                
   myFeatureLayer.queryIds(query, lang.hitch(this, function(objectIds) {  
    myFeatureTable.selectedRowIds = objectIds;  
    myFeatureTable._showSelectedRecords(); 
   }));  
}); 

Thank you,

André

0 Kudos
AndréRibeiro
New Contributor II

I already did it, thank you so much!

Now I'm struggling with one thing more. I query the feature table records, but I want to query the records on map too, on feature layer, how can I achieve that?

0 Kudos
TomSellsted
MVP Regular Contributor

André,

Are you wanting to highlight the selected features on the map?  You can easily highlight them by setting a selection symbol.  Here is the documentation that might help with that:

FeatureLayer | API Reference | ArcGIS API for JavaScript 3.19 

Regards,

Tom