Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kim Larsen 29 posts 72 karma points
    Apr 19, 2011 @ 02:31
    Kim Larsen
    0

    Dynamically calculated property

    Im not sure where to put this as it probably can be solved in many ways but here it goes;

    I have en document type where I need to dynamically calculate af valueproperty each time it is shown - Im using a XSLT macro to show the list of items so as far as I know I cannot include an .NET macro inside the XSLT so this it not an option, another way was to use the SQL for XSLT (from jesper.com) but it seems not to work when using SQL CE. I have also tried building my own extension but I cannot find af why to return XPathNodeIterator when using an SqlCeConnection.

    What I need to calculate are some userinput saved in my own table structure.

    So how can I show my calculated value?

  • Rich Green 2246 posts 4008 karma points
    Apr 19, 2011 @ 08:55
    Rich Green
    0

    Hi Kim, Is it just one value that gets calculated? If so you could add another field to your doc type and calculate and update this field when the node gets published. Then you can just use this value directly in your template or xslt. Hope I understood your problem correctly. Rich

  • Kim Larsen 29 posts 72 karma points
    Apr 19, 2011 @ 09:16
    Kim Larsen
    0

    It is only one value for each item. The calculated value will constantly change so I cannot depend on the webmaster to constantly republish all items to get an updated value - the value must be realtime.

  • Rich Green 2246 posts 4008 karma points
    Apr 19, 2011 @ 09:22
    Rich Green
    0

    You were right to say there would be many ways to retrieve a dynamic value back, you could use Base, direct database access, web service. Perhaps if you explains more about what the calculation is then it might become clearer. If the value changes it seems that it's based on other figure/figures that change, perhaps like an exchange rate? Where are these figures held? In a database, how are they updated? Sorry to answer your question, with more questions.. Rich

  • Kim Larsen 29 posts 72 karma points
    Apr 19, 2011 @ 09:49
    Kim Larsen
    0

    The values are stored in the same database as Umbraco but using my own tables - there are different values to be calculated depending on document type, what the values contain differs a lot; it can be an avarage rating (users can rate items), the number of comment. The extra data are added using .NET usercontrols.

    Maybe it is possible to create an .NET macro to loop through the items instead of an XSLT?

  • Eran Meir 401 posts 543 karma points
    Apr 19, 2011 @ 09:52
    Eran Meir
    0

    you can call a .net macro to iterate the items, another option is that you can call another macro inside xslt macro

  • Rich Green 2246 posts 4008 karma points
    Apr 19, 2011 @ 10:04
    Rich Green
    0

    As Eran states, if you are comfortable making .net usercontrols then this is certainly a good option.

    You can just use the nodeFactory http://our.umbraco.org/wiki/reference/api-cheatsheet/working-with-the-nodefactory to grab your Umbraco data, then directly access your database data in the way you normally would to make the calculations.

    Rich 

  • Kim Larsen 29 posts 72 karma points
    Apr 26, 2011 @ 09:33
    Kim Larsen
    0

    Creating .NET usercontrols was easy! thanks!

  • Eric Schrepel 161 posts 226 karma points
    Mar 05, 2013 @ 05:19
    Eric Schrepel
    0

    Is there a sweet-n-easy Razor way to do sort a node collection on a custom (calculated) property?

    Example: we have a text field ReportNumber which mostly looks like a year then 1- or 2-digit number, so 1997-1, 2000-23, 2012-05, etc. We'd use two fields, but sometimes that initial field has a prefix like ISRP 1997-1, or ISAB 1995-12, and we'd rather not confuse users by having them split input into multiple fields.

    So on the back end (in pre-Umbraco days) I'd create a calculated field in SQL to create a sort order from the ReportNumber, then we'd OrderBy on that. But not sure how to do the same using the Model.OrderBy() structure in Umbraco.

    Or we're maybe supposed to apply a custom sort on the returned collection of nodes?

    Such a newbie to a lot of this.

Please Sign in or register to post replies

Write your reply to:

Draft