Manipulation of data after ToDataSourceResult

4 posts, 1 answers
  1. Ed
    Ed avatar
    168 posts
    Member since:
    Sep 2013

    Posted 16 Apr 2014 Link to this post

    Using Kendo UI MVC Extensions and my grid retrieves several thousand records from the DB and I call ToDataSourceResult to do all the filtering, sorting, Skip/Take, etc.  I want to do some processing of the data in one of the columns after the call to ToDataSourceResult, specifically because I only want to process the data visible to the user (not all several thousand records).  The function I want to use takes the content of the column as a string and returns the formatted data as a string.  Is there a "Kendo UI" way to do this?

    Thanks in advance.
  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 18 Apr 2014 Link to this post

    Hello Ed,

    Basically you can either use a template column which will take care of the formatting:

    http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-use-a-javascript-function-in-a-column-client-template?

    Or you can use the mapping C# function which will be used to project the collection before it is serialized and send to the client.

    e.g.
    people.ToDataSourceResult(dsRequest, map => new { Fullname = string.Format("Full name is {0} {1}", map.FirstName, map.LastName})

    I hope this helps.

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Rui
    Rui avatar
    1 posts
    Member since:
    Jul 2015

    Posted 19 Sep in reply to Petur Subev Link to this post

    How can I apply any of these alternatives to my scenario: we have a column that is the cumulative sum of the values of another column, in the VISIBLE rows.

    E.g. if I have 3 rows with values 1, 4, 8, the column I want will have the value 1 (first row's value), 5 (second row = 4 [value of second row] + 1 [cumulative value from first row]) and 13 (third row = 8 [value from third row] + 5 [cumulative result from second row]).

    The problem is that the cumulative sum must be performed AFTER any filtering is applied, that is, after ToDataSourceResult() call.

    How can I achieve it? I can do it before the call, as I have access to writable data, using a cycle through the entire contents. But, then, ToDataSourceResult() is called and I end up with a read-only IEnumerable.

    Thank you for your help.

  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 21 Sep Link to this post

    Hi Rui,

    Please refer to the answer in the support ticket that you have opened with the same question. If further assistance is needed I would suggest that we continue the conversation within the support ticket. 

    For other convenience, the data of the DataSourceResult is within its Data property, which allows further manipulation of the items.


    Best Regards,
    Konstantin Dikov
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
Back to Top
Kendo UI is VS 2017 Ready