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

CRUD operations clearing sorts and filters

2 Answers 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anderson
Top achievements
Rank 1
Anderson asked on 27 Feb 2014, 06:25 PM
Hi,

Currently, my grid clears any and all sort/filters applied to the grid after I perform any CRUD operation. I don't want to do that.
Can someone help?

I know that my ActionResult's return is not correct. I just don't know what should be there.

Here's my Controller
public class ItTasksController : Controller
   {
       private ITaskRepository _repository;
 
       public ItTasksController() : this(new TaskRepository()){
 
       }
 
       public ItTasksController (ITaskRepository repository){
           _repository = repository;
       }
 
       //
       // GET: /ItTasks/
       public ActionResult Tasks()
       {
           ViewBag.Message = "IT Dev Tasks";
           ViewBag.Link = "Tasks";
 
           var itTasks = new ItTasksDataContext().tnTasks;
 
           return View(itTasks);
       }
 
       [AcceptVerbs(HttpVerbs.Post)]
       public ActionResult Create([DataSourceRequest] DataSourceRequest request, TaskModel task)
       {
           if (ModelState.IsValid)
           {
               _repository.InsertTask(task);
           }
           return RedirectToAction("Tasks");
       }
 
       [AcceptVerbs(HttpVerbs.Post)]
       public ActionResult Read()
       {
           return RedirectToAction("Tasks");
       }
       [AcceptVerbs(HttpVerbs.Post)]
       public ActionResult Update([DataSourceRequest] DataSourceRequest request, TaskModel task)
       {
         
           if (ModelState.IsValid)
           {
               _repository.UpdateTask(task);
           }
           return RedirectToAction("Tasks");
       }
 
       [AcceptVerbs(HttpVerbs.Post)]
       public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, int taskID)
       {
           if (ModelState.IsValid)
           {
               _repository.DeleteTask(taskID);
           }
           return RedirectToAction("Tasks");
       }
   }

2 Answers, 1 is accepted

Sort by
0
Anderson
Top achievements
Rank 1
answered on 27 Feb 2014, 11:04 PM
Did a quick and dirty fix.

Just chopped off the KendoGrid-mode from the URL and sent it back.
0
Accepted
Kiril Nikolov
Telerik team
answered on 28 Feb 2014, 01:00 PM
Hello Anderson,

In general when you have a Kendo UI Grid with server operations all the sorting and filtering is done on the server and not on the client. This is why when you edit an item in your grid the sorting is not applied automatically, but you need to call the read() in order to get the sorted data from your remote service. For this purpose you can call the read() of the dataSource on the sync() event (thrown when the data is updated on the server), so you can get again the sorted data. 

Other approach will be to preserve the sorting and filtering and apply the same on the dataBound event, so you can again sort and filter the grid. All these methods and events are explained in the following API reference:

http://docs.telerik.com/kendo-ui/api/framework/datasource#events-sync

Regards,
Kiril Nikolov
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
Anderson
Top achievements
Rank 1
Answers by
Anderson
Top achievements
Rank 1
Kiril Nikolov
Telerik team
Share this question
or