Filtering does not work on the telerik mvc grid

1

This is my code that shows the network when the page loads.

When I enter the text to filter, it says there are no records to show.

@model IEnumerable<SAReds.UI.Web.Models.DepartmentModel>

 @(Html.Telerik().Grid<SAReds.UI.Web.Models.DepartmentModel>(Model)
     .Name("Grid")
         .DataKeys(keys =>
         {
             keys.Add(o => o.Id);
         })
     .Columns(columns =>
     {
         columns.Bound(o => o.CompanyName).Title("Company Name").Width(150);
         columns.Bound(o => o.Name).Title("Department Name").Width(150);
         columns.Bound(o => o.Active).Width(100).Title("Active");
         columns.Template(o => Html.ActionLink("Edit", "EditDepartment", new { o.Id })).Width(35)
         .ClientTemplate("<a href=\" " + Url.Action("EditDepartment", "Task") + "/<#= Id#>\">Edit</a>")
         .Title("Edit");
     })
        .DataBinding(dataBinding =>
        {
            dataBinding.Server().Select("CompanyDepartment", "Task", new
            {
                ajax =
                ViewData["ajax"]
            });
            dataBinding.Ajax().Select("_CompanyDepartment",
                "Task").Enabled((bool)ViewData["ajax"]);
        })
       .Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
       .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
       .Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
       .Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
       .Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
       .Footer((bool)ViewData["showFooter"]) )

driver code

public ActionResult CompanyDepartment(bool? ajax, bool? scrolling, bool? paging, bool? filtering, bool? sorting,bool? grouping, bool? showFooter)
{
        ViewData["ajax"] = ajax ?? true;
        ViewData["scrolling"] = scrolling ?? true;
        ViewData["paging"] = paging ?? true;
        ViewData["filtering"] = filtering ?? true;
        ViewData["grouping"] = grouping ?? true;
        ViewData["sorting"] = sorting ?? true;
        ViewData["showFooter"] = showFooter ?? true;


        IDataOperations ops = DataSession.GetDataOperations(null);
        List<Department> Depts = new List<Department>();
        List<Employee> employeeList = new List<Employee>();
        ops.Load(Depts).Select("*").From("Department");
        ops.Commit();
        //Employee employee = new Employee();
        Company company = new Company();
        ops.Load(employeeList);
        ops.Commit();

        List<DepartmentModel> deptModel = new List<DepartmentModel>();
        foreach(Department dp in Depts)
        {
            ops.Load(company).FilterColumns("Id").Values(new { Id = dp.CompanyId });
            ops.Commit();

            deptModel.Add(new DepartmentModel()
            {
                Id = dp.Id,
                CompanyId = dp.CompanyId,
                Active = dp.Active,
                Name = dp.Name,
                CompanyName = company.Name
            });
        }

        return View(deptModel);
    }

    [GridAction]
    public ActionResult _CompanyDepartment()
    {

        IDataOperations ops = DataSession.GetDataOperations(null);
        List<Department> Depts = new List<Department>();
        ops.Load(Depts).Select("*").From("Department");

        List<DepartmentModel> deptModel = new List<DepartmentModel>();
        foreach (Department dp in Depts)
        {
            deptModel.Add(new DepartmentModel()
            {
                Id = dp.Id,
                CompanyId = dp.CompanyId,
                Active = dp.Active,
                Name = dp.Name
            });
        }

        return View(new GridModel<<SAReds.UI.Web.Models.DepartmentModel>>
        {
            Data = deptModel
        });
    }    

Please help. Thank you.

    
asked by 01.05.2016 в 15:35
source

1 answer

0

I do not quite understand the logic of why there are times you use server binding and other ajax binding (I do not know exactly the version of Telerik that you are using, but I suppose that this documentation is the one that averages to your version given what I see in your code)

I would try to test if it is not something related to data binding that does not know which one to use when performing the filter. I would try using only server binding then just ajax binding and in case the two forms work, in that case I would try with the enable / disable logic of these methods.

I know it does not answer your question exactly but I hope it helps.

Greetings

    
answered by 10.05.2016 в 02:27