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

[Solved] Sort Grid's filterable multi checkbox

3 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 21 Mar 2015, 01:34 PM
Is there a way to sort the list of choices in a multi checkbox filterable?

Thanks in advance for your answer.

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 23 Mar 2015, 03:08 PM
Hello Brett,

You can do this however you need to provide dataSource for the filterable configuration.

e.g.

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.filterable.cell.dataSource

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Brett
Top achievements
Rank 1
answered on 23 Mar 2015, 03:13 PM
I tried this but it didn't get the unique value of the dataSource.  Values were repeated.

Is this the expected behavior?
0
Petur Subev
Telerik team
answered on 24 Mar 2015, 09:12 AM
Hello Brett,

Yes, the built-in dataSource that is generated cannot be sorted, so you need to provide your own dataSource where you should also take care to show only unique values.

We have a demos that show how to provide unique values when using the different MVC wrappers. Here is an example from the .NET framework

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Kendo.Mvc.Examples.Models;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System.Reflection;
 
namespace Kendo.Mvc.Examples.Controllers
{
    public partial class GridController : Controller
    {
        public ActionResult Filter_Multi_Checkboxes()
        {
            return View();
        }
 
        public ActionResult Unique(string field)
        {
            var result = GetEmployees().Distinct(new EmployeeComparer(field));
 
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
 
    public class EmployeeComparer : IEqualityComparer<EmployeeViewModel>
    {
        private string field;
 
        private PropertyInfo prop;
 
        public EmployeeComparer(string field)
        {
            this.field = field;
            prop = typeof(EmployeeViewModel).GetProperty(field);
        }
 
        public bool Equals(EmployeeViewModel x, EmployeeViewModel y)
        {
            return prop.GetValue(x, null).Equals(prop.GetValue(y, null));
        }
 
        public int GetHashCode(EmployeeViewModel obj)
        {
            return prop.GetValue(obj, null).GetHashCode();
        }
    }
}


Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Brett
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Brett
Top achievements
Rank 1
Share this question
or