This question is locked. New answers and comments are not allowed.
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
0
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:
And then set this data source to the dataSource property of the list view:
I hope this helps. Do not hesitate to contact us in case you need further assistance.
Regards,
Adrian
Telerik
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
Thanks
0
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:
Here is the code snippet from my previous response written in C#:
I hope this helps. If you need further assistance do not hesitate to contact us.
Regards,
Adrian
Telerik
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
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
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.