Editor Widget (how do I limit records in the data grid?)

1119
12
11-16-2011 08:41 AM
JerryBiedenbender
New Contributor
I was wondering if there was a way to limit the records that show up in the data grid. Right now everything in the layer shows up in the grid. Is it possible to not show a record in the grid that has a status as "complete" in one of the fields. Or only populate the data grid by a date range, (only records that have a date no older than a week or something?)


Thanks,
Jerry
0 Kudos
12 Replies
JenniferNery
Esri Regular Contributor
Are you using FeatureDataGrid? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid. If yes, you can set FilterSource property with Linq query.

 MyDataGrid.FilterSouce = (from g in l.Graphics
      where g.Attributes.ContainsKey("status") && (string)g.Attributes["status"] == "completed"
      select g).ToList();
0 Kudos
JerryBiedenbender
New Contributor
Is this where I'm suppose to add the code?

  private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args) 

FeatureLayer featureLayer = sender as FeatureLayer; 
args.Graphic.Select(); 


args.Graphic.Selected = !args.Graphic.Selected; 
if (args.Graphic.Selected) 
MyDataGrid.ScrollIntoView(args.Graphic, null); 

MyDataGrid.  FilterSouce = (from g in   l.Graphics 
where g.Attributes.ContainsKey("status") && (string)g.Attributes["status"] == "completed" 
select g).ToList(); 
  


}


When I add it here I get two errors....

1. 'ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid' does not contain a definition for 'FilterSouce' and no extension method 'FilterSouce' accepting a first argument of type 'ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid' could be found (are you missing a using directive or an assembly reference?)

2. The name 'l' does not exist in the current context
0 Kudos
JerryBiedenbender
New Contributor
Modified to be blank2
0 Kudos
JenniferNery
Esri Regular Contributor
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client.Toolkit~ESRI.ArcGIS.Client.To...

Where you place the code-snippet is really an application logic. Maybe on a button-click? Whenever you want the filter to be applied to your current FeatureDataGrid.Items. "l" is the FeatureLayer, assuming you have already set this variable. (i.e. var l = MyMap.Layers["MyFeatureLayerId"] as FeatureLayer, or var l = MyDataGrid.GraphicsLayer). Also make sure you have "using System.Linq". The code-snippet also assumes FeatureLayer.OutFields include "status" and your service field type defined this as string where "completed" could be a possible value. You can read up on how to use linq queries here: http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
0 Kudos
JerryBiedenbender
New Contributor
I almost have this figured out, Just one last hang up.

private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)
        {
            FeatureLayer featureLayer = sender as FeatureLayer;
            args.Graphic.Select();


            var l = MyMap.Layers["Dispatch"] as FeatureLayer;

            args.Graphic.Selected = !args.Graphic.Selected;
            if (args.Graphic.Selected)
                MyDataGrid.ScrollIntoView(args.Graphic, null);

            MyDataGrid.FilterSouce = (from g in l.Graphics
                                      where g.Attributes.ContainsKey("status") && (string)g.Attributes["status"] == "completed"
                                      select g).ToList();
   


        }


I am getting an error on this piece of code... See below


'ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid' does not contain a definition for 'FilterSouce' and no extension method 'FilterSouce' accepting a first argument of type 'ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid' could be found (are you missing a using directive or an assembly reference?)


Is there a specific reference that I need to add?

Thanks,
Jerry
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Strange.

Which SL API version are you using? (FilterSource is there for a while, but...)
0 Kudos
JerryBiedenbender
New Contributor
Silverlight 2.2
0 Kudos
JerryBiedenbender
New Contributor
I was able to get the (FilterSource) to stop having an error. After reading back into this post I realized we are putting this on a button click. I really would rather it just happen and not be on a button click. I just want the grid to show every record that does not have a status of "complete"



Thanks,
Jerry
0 Kudos
JerryBiedenbender
New Contributor
Is it possible for me to add a filter source code on my MainPage.xaml to exclude the grid results that have the status of complete? Below is where I think it would be added but im not sure how to write it.


<esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch"
                              Map="{Binding ElementName=MyMap}"
                              GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[Dispatch]}"
                              Width="Auto" />
0 Kudos