Hi
I'd like to get an example of sorting multiple columns in a grid using C#.
Thanks
Kathy
Hi Kathy,
Sure, i'd be happy to help.
Assuming you're using an IGGridViewDataSourceHelper, you just need to create IGGridViewSortedColumn objects and assign them to your IGGridViewDataSourceHelper. like this:
dsh.SortedColumns.AddObjects(new NSObject[]{new IGGridViewSortedColumn ("firstName", IGGridViewSortedColumnDirection.IGGridViewSortedColumnDirectionAscending), new IGGridViewSortedColumn ("lastName", IGGridViewSortedColumnDirection.IGGridViewSortedColumnDirectionAscending)});
In the code above, all i'm doing is creating 2 new sorted column objects. The first is my firstName property and the second is my lastName property. The order you assign to the SortedColumns collection determines the order the sort is applied. So in this case firstName is sorted first and then lastName is a sub sort applied to objects that have the same firstName.
You can read more about this feature here:
http://help.infragistics.com/iOS/2013.2/?page=IGGridView_Sorting_Columns.html
And, if you're interested in learning how sorting in objective-c actually works, I wrote a blog on it not long ago.
http://es.infragistics.com/community/blogs/stevez/archive/2013/10/16/ios-objective-c-sorting-an-array.aspx
Hope this helps,
-SteveZ
Hi Steve,
I am not using the data source helper (I did see the information you are referring to in the documentation). Can you let me know how to add the sorted columns to a weakdatasource?
WeakDataSource is just a property on the IGGridView.
So you'll just create your IGGridViewDataSourceHelper. Add your IGGridViewSortedColumn objects to the SortedColumns property on that datasource helper. And then set your IGGridView's WeakDataSource property to the instance of your dataSourceHelper.
_gridView = new IGGridView();
.... // Setup GridView
this.View.AddSubView(_gridView);
_dsh = new IGGridViewDataSourceHelper();
... // Setup Data
_dsh.SortedColumns.Add(// Add your SortedColumns objects like i previously demonstrated)
_dsh.Data = yourDataArray;
_gridView.WeakDataSource = _dsh;
I am not using the DataSourceHelper, I am using a custom IGGridViewDataSource.
Ah Sorry, i misread.
If you're not using a DataSourceHelper, then you're providing the data to the gridView manually. So all you have to do is sort the data yourself.
Basically, every cell that you create, you're controlling what data is presented. I'm assuming you're using an array in your custom DataSource. So just sort the array and use that to populate the grid.
Out of curiosity, is there a particular reason you're not using a DataSourceHelper?
I'm trying to use the DataSourceHelper for the IGGrid using C# to take advantage of the built in sorting and filtering
I originally created a custom IGdatasource and passed in a double array and have it working great. My data contains images and text. I'm having trouble figuring out what exactly the DataSource helper wants as a data structure. All of the examples I find in the Infragistics documentation refer to data but do not show how this sample data is actually set up so I don't know what all the references are and how the data (itself) and the DataSourcehelper are actually connected. The datasourcehelper apparently requires an NSArray as imput. All of the examples that I can find seem to be one column examples. Can you just give me an example of how to set up an NSObject that has multiple columns that the DataSourceHelper will accept? For instance in the Nuclios app example on grid sorting which uses the igSalesmanitem to generate data, it would be helpful to see how that data is set up (in C#) to be able to populate my grid with the DataSourceHelper
Sure, np.
I've attached the iGSalesmanItem class, converter to C#.
You just need to make sure you export your properties.
Also, here is a code snippet showing the grid consuming that data with an image column:
IGGridView grid = new IGGridView (this.View.Bounds, IGGridViewStyle.IGGridViewStyleDefault); grid.Theme = new IGGridViewDarkTheme (); grid.RowHeight = 150; grid.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; this.View.AddSubview (grid); IGGridViewImageColumnDefinition col = new IGGridViewImageColumnDefinition ("image", IGGridViewImageColumnDefinitionPropertyType.IGGridViewImageColumnDefinitionPropertyTypeImage); col.TextFieldKey = "firstName"; col.TextAlignment = UITextAlignment.Center; IGGridViewSingleFieldMultiColumnDataSourceHelper dsh = new IGGridViewSingleFieldMultiColumnDataSourceHelper (col); dsh.NumberOfColumns = 5; dsh.Data = IGSalesmanItem.GenerateData (200).ToArray (); grid.DataSource = dsh;