This is a migrated thread and some comments may be shown as answers.

Alphabetically grouped ContactList through TKListView

5 Answers 79 Views
ListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Burzin
Top achievements
Rank 1
Burzin asked on 09 Feb 2016, 01:05 PM
Actually I am using a Telerik ListView to create a contactList which will be grouped according to the initials of the contact name as illustrated in the attachment. I cant figure out how to achieve this. Please help!

5 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 11 Feb 2016, 03:25 PM
Hello, Burzin,

Thank you for contacting us.

You can achieve this scenario using TKDataSource as data source to the list view and add a group descriptor. Consider the code snippet below:
_dataSource = [TKDataSource new];
    [_dataSource addGroupDescriptor:[[TKDataSourceGroupDescriptor alloc] initWithBlock:^id(id item){
        // return group key - the first letter from the name
        NSString *key = [(NSString *)item substringToIndex:1];
        return key;
    } comparator:^NSComparisonResult(TKDataSourceGroup *obj1, TKDataSourceGroup *obj2) {
        // compare group keys so they can be in alphabetical order
        NSComparisonResult result = [obj1.key compare:obj2.key];
        return result;
    }]];
    [_dataSource loadDataFromJSONResource:@"ListViewSampleData" ofType:@"json" rootItemKeyPath:@"players"];

And then set this data source to the dataSource property of the list view:
listView.dataSource = _dataSource;

I hope this helps. Do not hesitate to contact us in case you need further assistance.

Regards,
Adrian
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Burzin
Top achievements
Rank 1
answered on 12 Feb 2016, 05:11 AM
Can we use TKDataSource for custom Cells of TKListView ? Also I am using Xamarin so can you please post c# code.
Thanks
0
Adrian
Telerik team
answered on 17 Feb 2016, 08:04 AM
Hi, Burzin,

I apologize for the late response.

Yes you can use TKDataSource to return custom list view cells. You should use the CreateCell method. Consider the code below:
this.dataSource.Settings.ListView.CreateCell (delegate (TKListView list, NSIndexPath indexPath, NSObject item){
    // return your cell;
});

Here is the code snippet from my previous response written in C#:
TKDataSourceGroupDescriptor descriptor = new TKDataSourceGroupDescriptor (delegate (NSObject item) {
                NSString key = new NSString((item as NSString)[0].ToString());
                return key;
            }, delegate (NSObject obj1, NSObject obj2) {
                NSComparisonResult res = ((obj1 as TKDataSourceGroup).Key as NSString).Compare(((obj2 as TKDataSourceGroup).Key as NSString));
                return res;
            });
 
            this.dataSource.AddGroupDescriptor (descriptor);
            this.dataSource.LoadDataFromJSONResource ("ListViewSampleData", "json", "players");

I hope this helps. If you need further assistance do not hesitate to contact us.

Regards,
Adrian
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 1
answered on 06 Feb 2017, 02:21 PM

I have problem with Group.

I have name list. I've added "Group" column to my data. If I put only first letter to Group column, i see names grouped "a".."z". The names itself are NOT sorted!

If I put FullName in Group, I see names SORTED, but each name has own group :(

I tried GroupWithKey("Group", CompFunc) and AddGroupDescriptor(descriptor) like describes... nothing works. Sort on grouped DataSource also dont work.

0
Deyan
Telerik team
answered on 08 Feb 2017, 11:12 AM
Hello,

Thanks for writing.

To have the items sorted by name you will have to first add a Sort descriptor and sort by name, then add the Group descriptor and group by first letter. Remember that descriptors are processed in the order they are added.

Here's more information:

http://docs.telerik.com/devtools/ios/datasource/data-shaping

Regards,
Deyan
Telerik by Progress
Want to build beautiful Android apps as well? Check out UI for Android which enables the same set of scenarios, allowing you to create the same great app experience on both iOS and Android.
Tags
ListView
Asked by
Burzin
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Burzin
Top achievements
Rank 1
David
Top achievements
Rank 1
Deyan
Telerik team
Share this question
or