NetSuite高级PDF布局:实现商品列表横向排列需求
NetSuite Advanced PDF: Horizontal Grid Layout for Line Items
Hey there! I see you're new to NetSuite and trying to switch your sales order line items from a vertical list to a horizontal grid in your Advanced PDF layout. Your current code is set up for one item per row, so let's adjust that to get the grid look you want.
Key Changes Needed
Instead of creating a full table row for each item, we'll group multiple items into a single table row, with each item taking its own column. Here's how to make that happen:
- Define how many items you want per row (I’ll use 3 as an example, but you can tweak this)
- Use the
item_indexto trigger a new table row every N items - Wrap all an item’s details (code, qty, description, etc.) inside a single table column
- Fill empty columns in the last row to keep the grid aligned neatly
Modified Code
Here’s your updated code with these changes applied:
<body padding="8mm 13mm 8mm 13mm" size="A4"> <#if record.item?has_content> <#-- Set how many items to display per horizontal row --> <#set $itemsPerRow = 3> <table class="itemTable" width="100%" cellpadding="6" cellspacing="0"> <#-- Optional header row with column labels for each grid item --> <thead> <tr> <#list 1..$itemsPerRow as col> <th style="border-bottom: 1px solid #000;"> <table width="100%"> <tr> <th width="15%">Code</th> <th width="10%">Qty</th> <th width="10%">Units</th> <th width="45%">Description</th> <th width="10%">Unit Price</th> <th width="10%">Amount</th> </tr> </table> </th> </#list> </tr> </thead> <tbody> <#-- Loop through items and group into rows --> <#list record.item as item> <#-- Start a new table row every N items --> <#if item_index % $itemsPerRow == 0> <tr> </#if> <#-- Each item gets its own column with all details --> <td width="${100/$itemsPerRow}%" style="border-bottom: 1px solid #eee;"> <table width="100%"> <tr> <td width="15%"><@printCode item.item /></td> <td width="10%">${item.quantity}</td> <td width="10%">${item.units}</td> <td width="45%">${item.description}</td> <td width="10%"> <#if item.rate?is_number>${item.rate?string("#,##0.00")}<#else>${item.rate}</#if> </td> <td width="10%"> <#if item.amount?is_number>${item.amount?string("#,##0.00")}<#else>${item.amount}</#if> </td> </tr> </table> </td> <#-- Close the row when we hit the end of a group, or end of the item list --> <#if (item_index + 1) % $itemsPerRow == 0 || item_has_next == false> <#-- Add empty columns if the last row isn't full --> <#set $remainingCols = $itemsPerRow - ((item_index + 1) % $itemsPerRow)> <#if $remainingCols != $itemsPerRow> <#list 1..$remainingCols as emptyCol> <td width="${100/$itemsPerRow}%" style="border-bottom: 1px solid #eee;"> </td> </#list> </#if> </tr> </#if> </#list> </tbody> </table> </#if> </body>
Quick Customization Tips
- Change
$itemsPerRowto adjust how many items fit in each row (e.g., 2 for wider columns, 4 for more items per row) - Tweak the width percentages in the inner tables to adjust spacing for each item field
- Remove the
<thead>section if you don’t want header labels above each grid column - Adjust border/padding styles in the
styleattributes to match your desired visual look
Test this out in NetSuite’s PDF preview to fine-tune the alignment and spacing until it matches your target grid layout!
内容的提问来源于stack exchange,提问作者Joseph GelliWelli
相关产品推荐
相关产品推荐

