Sort rows by property that does not have an own database row

  • Hi there,


    I would like to solve a problem:


    Sorting rows in the Pagekit-views is super easy:


    If your model has a property, you can just do:


    PHP: ItemApiController.php
    1. if ( preg_match( '/^(title|url)\s(asc|desc)$/i', $order, $match ) ) {
    2. $order = $match;
    3. } else {
    4. $order = [ 1 => 'title', 2 => 'asc' ];
    5. }



    In your view you can just do


    HTML: item-index.php
    1. <th class="pk-table-min-width-200"
    2. v-order:title="config.filter.order">{{ 'Title' | trans }}
    3. </th>
    4. <th class="pk-table-min-width-200"
    5. v-order:url="config.filter.order">{{ 'URL' | trans }}
    6. </th>



    Alright, that works fine.


    But what's about a model that has something like a "computed" property. For example you create a value in the model that is not stored in a database row. How would you do the sorting for this?


    E.g.



    You have a row date and modified. Now you would like to create a field that contains the difference between date and modified. Let's call this value difference.


    Now you want to echo out this value in a view and also make this work with v-order . Is this possible in an easy way?