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

ToDataSourceResult with additional value(s)

3 Answers 989 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 20 Feb 2018, 01:22 PM

Hello,

is there any possibility to add an additional value to the ToDataSourceResult in the Kendo read Action to pass that value with
the Ajax request to the Client?

return Json(result.ToDataSourceResult(request));

 

Background: we have a paged grid and in my action I pass the ID of a row which is added to the database with a Ajax form outside the grid
and calculate on the Server the page for that row so I want to pass that page as an additional value to the client:
https://www.telerik.com/forums/find-row-and-select-it-in-grouped-sorted-and-paged-grid#nF26Ya0-hkqiWAdfUkaSuQ

robert

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 23 Feb 2018, 07:25 AM
Hello, Robert,

Inside the Read action in the Controller create a custom Json result based on the result of the ToDataSourceResult method and the additional value:

var result /// get the data;
  
var resultFinal = result.ToDataSourceResult(request);
            return Json(new
            {
                Data = resultFinal.Data,
                Total = resultFinal.Total,
                AggregateResults = resultFinal.AggregateResults,
                Errors = resultFinal.Errors,
                myProperty1 = "extra value", // Add the extra value
            });

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 23 Feb 2018, 08:41 AM

Hello,

where is the best Event to get the myProperty1 value?

is it also possible to get the value in the dataBound Event?

 

robert

0
Accepted
Georgi
Telerik team
answered on 28 Feb 2018, 07:22 AM
Hello Robert,

The dataSource requests the server, then maps the response and populates the grid. Therefore, the raw response from the server can be accessed in the requestEnd event of the dataSource.

e.g.

function onRequestEnd(e) {
       var myProperty = e.response.MyProperty1;
    }


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Stefan
Telerik team
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Georgi
Telerik team
Share this question
or