Announcement

Collapse
No announcement yet.

PDF Template Sorting of child records

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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,

  • #2
    Hello,

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

    Regards

    Comment


    • rinorway
      rinorway commented
      Editing a comment
      Yes, I can confirm that is correct indeed. Thank you.

  • #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...
    X