PDF Template Sorting of child records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rinorway
    Senior Member
    • Feb 2016
    • 179

    PDF Template Sorting of child records

    How do you sort child records in a PDF template?

    Eg : I want to order the items of default sales order on the name.

    Code:
    <!-- {{#each itemList}} --> <tr>
    <td>{{order}}</td>
    <td>{{name}}</td>
    <td>{{quantity}}</td>
    </tr>
    <!-- {{/each}} -->
    doc : https://docs.espocrm.com/user-guide/printing-to-pdf/
    possibly you can use the index helper of handlebars

    but it is not clear how that would work in this context.

    Thank you,
  • item
    Active Community Member
    • Mar 2017
    • 1476

    #2
    Hello,

    for me, in entityManager.. you have orderBy field .. and i think pdf template take this parameter for order.

    Regards
    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

    Comment


    • rinorway
      rinorway commented
      Editing a comment
      Yes, I can confirm that is correct indeed. Thank you.
  • rinorway
    Senior Member
    • Feb 2016
    • 179

    #3
    In addition you might use custom template helpers as described in


    Eg : From a contact, give a list of meetings ordered by startdate

    PHP Code:
    public static function dumpMeetingItems()
    {
    $args = func_get_args();
    $context = $args[count($args) - 1];
    $hash = $context['hash'];
    $data = $context['data']['root']['meetings'];
    
    // sort the meetings on date
    $key='dateStart';
    usort($data, function ($a, $b) use ($key) :int {
    return $a[$key] <=> $b[$key];
    });
    
    $html = "<ul>";
    foreach($data AS $key => $value) {
       $html.="<li>".$value['dateStart']."-".$value['name']</li>";
    }
    $html.= "</ul>";
    return new LightnCandy\SafeString($html);
    } 
    

    Comment

    Working...