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

Making Datasource requests after leaving grid view

9 Answers 251 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 27 Feb 2015, 04:02 AM
I am using MVC5 and razor views with a kendo grid using ajax.  I generate a IEnumerable list of data for the grid.  When user hits button on grid the controller gets notified and opens up an edit view for the row that was clicked.

What i want to be able to do is send data to that edit view so that it can move to next or previous record in the dataset that was in the grid.  I have achieved this by sending the id data from the displayed rows to the edit view via Viewbag.  I was able to learn how to send the viewsource data in the grid to the controller from this   thread

however if you hit "next" and get to the record which was the last row in the original grid, i want to be able to execute my own datarequest to grab another page of data, intercept that data and just parse out the row id information to use for additional next/prev activities.

i am stuck in figuring out how to make a new request on the original datasource now that i am not in the same view page.

is this possible?

9 Answers, 1 is accepted

Sort by
0
Jim
Top achievements
Rank 1
answered on 28 Feb 2015, 07:21 PM
just to be clear, posting the filter back to the controller wouldn't really get the job done, but i was trying to send datasource info back to the controller without any luck.
0
Atanas Korchev
Telerik team
answered on 03 Mar 2015, 07:09 AM
Hi Jeff,

In order to answer your question we need a better understanding of your implementation. Could you explain what "opens up an edit view" means? Do you open a new browser window? Or do you navigate to that edit view? Pasting the relevant code and grid declaration will also help.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jim
Top achievements
Rank 1
answered on 04 Mar 2015, 01:56 AM
ok, let me try to explain and boil it down.  I have a grid and it is filled with the results of a query (via ajax, using mvc5 and razor view engine).  

Let's say the results of that query would give me rows with id's of 2,4,6,8,10,12,14,16,18,20.
However the grid is only showing 5 rows per page, so the db query really only returned 2,4,6,8,10.

Each row has an "EDIT" button that when clicked calls the controller action to open in a new edit view page, with the model item data of the row that was clicked.  fyi, I am using my own editing pages, not the grid edit in place functionality.

When I edit the record for row id 4 (the second row in the grid) i am on new webpage different from the one that housed the grid view.  What i want to do on that new page is be able to know the last datasource request info from the grid prior to being directed to this new page.  From that new page, i can click a "Next" button which calls my controller "Next" action, and in that action i can use the old request info to advance the page and do a manual "ToDataSourceResult(request)" call against my db to pull another page of data to use in the controller action.

Whenever the grid makes a call to the controller class, I can save the request information in a private static variable in my controller, and access that static from the "Next" handler in the controller.  It does work, but in a multi-user server farm environment where this app will live, using a static is not going to work, as it will get corrupted by multiple simultaneous users.

I cannot figure out how to save the request info after i leave the grid page and pass it back to the controller when i call the "next" action from the "edit" page.

0
Jim
Top achievements
Rank 1
answered on 04 Mar 2015, 02:03 AM
I also tried saving the request information (DataSourceRequest object) as a field in my view model so when the ajax call into the controller (for getting new data for the grid), i take the request data and save it in each item in the enumerable model that i return to the view.  then when the "Edit" action calls into the controller, the model passed in will have the request data.

this idea fails because the ".ToDataSourceResult(request)" cannot convert the DataSourceRequest object

public ActionResult GridList([DataSourceRequest] DataSourceRequest request)
{
// Save this data request for future editing next/prev
request = new DataSourceRequest
         {
            Aggregates = request.Aggregates,
            PageSize = request.PageSize,
            Filters = request.Filters,
            Groups = request.Groups,
            Page = request.Page,
            Sorts = request.Sorts
          },
          nSelected = -1
          };
    
// populate my IEnumerable list of "questions", each adds the request object to each of the items in the list.
      var list = GetMyItems( request ).ToDataSourceResult( request );
      return Json( list );
   }
0
Jim
Top achievements
Rank 1
answered on 04 Mar 2015, 02:15 AM
the error is:  Additional information: Unable to process the type 'Kendo.Mvc.SortDescriptor[]', because it has no known mapping to the value layer.

i can't convert the collections inside datasourcerequest into json.
0
Atanas Korchev
Telerik team
answered on 05 Mar 2015, 08:38 AM

Hello Jeff,

You can try saving and restoring the grid state. When the user clicks the edit button save the state to local storage or a cookie. When the user goes back to the grid page load the state (if available).

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jim
Top achievements
Rank 1
answered on 05 Mar 2015, 07:17 PM
Hi Atanas, thanks for the idea, but i think you may have missed the point of my question.
I want the Datasource's last DataSourceRequest object to be passed onto the Edit view so when it posts to the controller, the controller can access that request, make some updates and then excercise the request against the db.

1.  The datasourcerequest gets sent from grid to controller to show return one page of records for grid.
2.  grid shows records.
3.  user clicks a grid record to go to a new edit view.  That is done via a call to the controller action.  
4.  I want that call to the controller action to be able to get the datasourcerequest object.
5.  the datasourcerequest object is then sent to the new edit view.
6.  when the edit view posts its form back to controller, i want the datasourcerequest object posted back with the form data to the controller's handler that handles edit view posts.

0
Jim
Top achievements
Rank 1
answered on 05 Mar 2015, 07:24 PM
I have the same question as the poster in this thread.

The answer was to serialize the datasource.view() and send that back to the controller via ajax.
I don't want the DataSource.view() info, i want the DataSourceRequest object that generated the grid display....not just the results of that request.

I don't know how to get the request and serialize it back to the controller in this way.

I want this because i want the next view rendered by the controller to have access to the prior request so i can use that request to do my own gathering of a new page of data from the database, using all the same filters, sorting and aggregation info that went into the previous DataSourceRequest.

0
Atanas Korchev
Telerik team
answered on 06 Mar 2015, 09:24 AM

Hello Jeff,

In that case I will recommend the approach used in this project. It uses the parameter map of the ASP.NET MVC transport which knows how to encode the current data source state in a format which DataSourceRequest can parse.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Data Source
Asked by
Jim
Top achievements
Rank 1
Answers by
Jim
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or