Show find task results in a DataGrid

627
4
11-30-2012 07:04 AM
WeipingZeng
New Contributor II
I have two questions about the sample, "Show find task results in a DataGrid", under Find and Identify (http://help.arcgis.com/en/webapi/javascript/arcgis/samples/find_map_datagrid/index.html)

1. When searching, a return, which normally triggers a search, does not work. You actually have to hit the search button (some average persons do not know it). How can I make the return key triggers a search?

2. I have a website field that has url such as http://www.esri.com/. Currently we cannot click the link in the search table to open a website? How can I make it work?
0 Kudos
4 Replies
SteveCole
Frequent Contributor
With respect to your second question, you could accomplish this using a dojo listener event based on a row click event. Here's an example I'm using to zoom to a feature represented by a row in a datagrid:

 dojo.connect(dijit.byId("grid"), 'onRowClick', function(e) {
  var rowdata = grid.getItem(e.rowIndex);
  var theId = rowdata.OBJECTID;

  theFeatureLayer.clearSelection();
  var query = new esri.tasks.Query();
  query.objectIds = [theId];
  theFeatureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW,function(features){
   var theExtent = features[0].geometry.getExtent().expand(2.5);
   map.setExtent(theExtent);
  });
 });


In your situation, just swap the field name in my example (OBJECTID) for the name of your field containing the URL. The rest of the routine would be pure javascript to open a URL in a new window:

 //Get the screen resolution and scale it back 10% (for use with the new window)
var theWidth= 0.9 * screen.width;
var theHeight= 0.9 * screen.height;
var theOptions = 'height=' + theHeight + ',left=25,top=25,width=' + theWidth;
window.open(theUrl,'_blank',theOptions);
0 Kudos
PaulBushore
Occasional Contributor
Regarding your first question about a return causing a search. I gleaned this from a StackExchange post sometime. It sets a javascript function that determines if the key being pressed is the return key. If it is, it fires the button's click event. There may be better was of doing this though.

<script>
function searchOnReturn(e) {
   if (typeof e == 'undefined' && window.event) {
        e = window.event;
    }
    if (e.keyCode == 13) {
        dojo.byId('btnOwnerSearch').click();
    }
}
</script>

Owner name:<input type="text" id="ownerName" size="60" value="Katz" onkeypress="searchOnReturn(event);"/>



Hope this helps!
0 Kudos
WeipingZeng
New Contributor II
I tried your code to fix the first question. But the return key still does not work. Are there any typos in your codes?
0 Kudos
WeipingZeng
New Contributor II
Hi Paul. Thanks a lot. I modified your function searchOnReturn(e) and the first question works now.
   function searchOnReturn(e) {
       if (e.keyCode == 13) {
                                                     findParams.searchText = dojo.byId("ownerName").value;       
                                                     findTask.execute(findParams,showResults);
       }
   }
0 Kudos