Limit the number of table rows?

ill create purchase order. i order 30 items, but when i print, this what happen below.
how to set limit the number of rows?

Hi,
Try with this->











{%- for row in doc.items -%}







{%- endfor -%}

No Item Qty Rate Amount
{{ row.idx }} {{ row.item or ‘’ }}
{{ row.qty }} {{ row.rate }} {{ row.amount }}

@shraddha what i can try? thanks!

Hi @shraddha its empty ?

    <div class="row">
            <table class="table table-condensed table-hover table-bordered">
                <tbody>
                    <tr>
                        <th>No</th>
                        <th>Item</th>
                        <th>Qty</th>
                        <th>Rate</th>  
                        <th>Amount</th>
                        
                    </tr>
                    {%- for row in doc.items -%}
                        <tr>
                            <td style="width: 3%;">{{ row.idx }}</td>
                            <td style="width: 57%;"><b>{{ row.item or '' }} </b><br></td>
                            <td style="width: 10%; text-align: right;">{{ row.qty }}</td>
                            <td style="width: 10%; text-align: right;">{{ row.rate }}</td>
                            <td style="width: 10%; text-align: right;">{{ row.amount }}</td>
                        </tr>
                    {%- endfor -%}
                    </tbody>
            </table>
        </div>

hi! @shraddha still the same the row in table will continously i need to page break for every 12 items. i need to know on how to limit the number of rows?

Hi. Try this:

{% for row in doc.items %}

    {% if row.idx % 11 == 0 %}

    </table></div></div></div>
    <div class="page-break">
    <div class="row section-break">
    <div class="col-xs-12">
    <table class="table table-bordered items">
    <tr>

    {% endif %}

    // Your code here

{% endfor %}
4 Likes

hi thanks for the response @snv this what happen in my print format

this is my code.

  1. You don’t need <tr> in the if block if you are using it below.
  2. The no. of </div> in the if block depend on the no. of divs opened in your code. It is variable.

Maybe if you post you full code, we can resolve it better. :slight_smile:
Also, seems like something might be wrong with CSS customization (if any). Post that too if you made some customization in CSS.

PRO Tip: Paste your code and use “Preformatted text” option (Ctrl + Shift + C) instead of taking a screenshot.

<div class="page-break" style="border:1px solid #F5FFFA; width:100%; height:963px;">

  <strong>
     <div style="position:relative; margin-top:0px;">
	<img src="/files/RRD LOGO2.jpg" width="65%" height: 25px; style="float:left; position:absolute;">
	<div class="po">
           <p style="font-size:20px; text-align:center;">PURCHASE ORDER</p>
	     <table width="100%">	
	       <tr>
	  	 <th class="sn3">PO No :</td>
  		 <th class="sn3">{{ doc.name }}</td>
	       </tr>
	       <tr>
		 <td class="sn2">Date :</td>
		 <td class="sn2">{{doc.get_formatted("transaction_date")}}</td>
	       </tr>
	     </table>
	</div>
    </div>
  </strong>

  <table style= "width:100%; margin-bottom:10px; margin-top:160px;">
     <tr>
        <td class="sn">SUPPLIER :</td>
        <td class="sn1">{{doc.supplier}}</td>
        <td class="sn"></td>
        <td class="sn"></td>
     </tr>
     <tr>
        <td class="sn">ADDRESS:</td>
        <td class="sn1">{{doc.supplier_address}}</td>
        <td class="sn">TERMS :</td>
        <td class="sn">{{doc.credit_days}}&nbsp;days</td>
     </tr>
  </table>



  <div style="border: 1px solid black; height:405px; width:100%; font-size:12px;">
    <table style= "width:100%; border: 1px solid black;">
       <tr class="tb1">
         <th width="7%">NO</th>
         <th width="45%">ITEM</th>
         <th width="15%">QUANTITY</th>
         <th width="15%">RATE</th>
         <th width="18%">AMOUNT</th>
       </tr>
     </table>

     <table style="width:100%;">
     {%- for row in doc.items -%}
        <tr>
          <td style="text-align:center; width:7%;">{{ row.idx }}</td>
          <td align="left" width="45%;">{{row.item_name}}</td>
          <td style="text-align:center; width:15%;">{{row.get_formatted("qty")}}&nbsp;{{ row.uom}}</td>
     	  <td style="text-align:center; margin-right:5px; width:15%;">{{row.get_formatted("rate")}}</td>
    	  <td style="text-align:center; margin-right:5px; width:18%;">{{row.get_formatted("amount", doc)}}</td>
    	</tr>
    	{%-endfor-%}	
      </table>
      <p style="text-align:center;">************* Nothing Follows*************</p>
  </div>
        


    <table height="30px" width="100%">
	<tr style="border:1px solid black;">
	   <th class="total" style="background-color:#DCDCDC; font-size:13px;"><strong>SPECIAL INSTRUCTIONS / REMARKS</strong></td>
	   <td style="width:15%; font-size:12px;">DISCOUNT :</td>
	   <td style="width:20%;  text-align:right; font-size:12px;"> - &nbsp;&nbsp;{{doc.get_formatted("discount_amount",doc)}}</td>
	</tr>

	<tr style="border:1px solid black;">
	   <td class="total">{{doc.remarks}}</td>
	   
	   <th class="grand_total1" width="15%"><strong>TOTAL    :</strong></td>
	   <th class="grand_total2" width="20%"><strong>{{doc.get_formatted("grand_total",doc)}}</strong></td> 
	</tr>
    </table>



    <div>
     <p style="font-weight:bold; font-size:13px;margin-top:5px;">INSTRUCTION TO SUPPLIER:</p>
     <p>1. Please acknowledge immediately receipt on the attach copy.</p>
     <p>2. The acceptance and execution of this order by you implies acceptance of the terms and conditions stated herein.</p>
     <p>3. Please indicate P.O number on your invoice, delivery receipts and packing list.</p>
     <p>4. This purchase order must accompany your invoices and bill of lading upon presentation for payment.</p>
     <br><br>
     <p style="font-weight:bold; font-size:13px;"> P.O. ACKNOWLEDGED BY:</p>
     <br>
     <br>
    </div>



  <div class="feeter">
    <table width="100%">
	<tr>
     	   <td class="signs1">{{doc.creator2}}</td>
     	   <td class="signs"></td>
     	   <td class="signs1">Jimmy Lim</td>
     	   <td class="signs"></td>
     	   <td class="signs1">Joseph Chan</td>
	</tr>
	<tr>
     	   <td class="signs_a">PREPARED BY</td>
     	   <td class="signs"></td>
     	   <td class="signs_a">NOTED BY</td>
     	   <td class="signs"></td>
     	   <td class="signs_a">APPROVED BY</td>
	</tr>
    </table>
  </div>



</div>
.po
{
	float: right;
	position:absolute;
	margin-left:65%;
	width:35%;
	margin-top:20px;
}

.grand_total1
{
         font-size:16px;
	 text-align:left;
}


.grand_total2
{
         font-size:16px;
	 text-align:right;
}

.sn3
{
	font-size:15px;
	text-align:center;
	border:1px solid black;
	background-color:#DCDCDC;
}

.sn2
{
	font-size:15px;
	text-align:center;
	border:1px solid black;
}

.sn1
{
	font-size:15px;
	text-align:left;
	width:55%;
}

.sn
{
	font-size:15px;
	text-align:left;
	width:15%;
}

th
{
	text-align:center;
	border:1px solid black;
}

.tb1
{
	background-color:#DCDCDC;
}

.feeter
{
	width:100%;
	text-align:center;
}

.signs
{
	width:5%;
	text-align:center;
}

.signs1
{
	width:30%;
	text-align:center;
	border-bottom:1px solid black;
}

.signs_a
{
	width:30%;
	text-align:center;
}

p
{
	font-size:11.5px;
}

.total
{
	border:1px solid black;
	width:65%;
}

@snv that is my full code.

and this is the template looks like.

That’s a nice template.

Here are my suggestions:

  • Don’t style th and p elements directly, it may cause issues with the rest of the site. Use a class instead.
  • The main reason for this is that you had given fixed height to div wrapping the items table.
  • Modify the code as follows:
    
NO ITEM QUANTITY RATE AMOUNT
{%- for row in doc.items -%} {% if row.page_break %}
{% endif %} {%-endfor-%}
NO ITEM QUANTITY RATE AMOUNT
{{ row.idx }} {{row.item_name}} {{row.get_formatted("qty")}} {{ row.uom}} {{row.get_formatted("rate")}} {{row.get_formatted("amount", doc)}}

************* Nothing Follows*************

ill try limit the table field per page. 11 rows per page but i had a problem this what happen?

this is my code:

and this is the output.

Please do not post a new thread when you have an existing thread for the same topic.

Did you try what I had suggested here?

Why do you want to limit the number to 11 per page?
Wouldn’t it make more sense to show instructions and sign only on the last page?

hi! @snv sorry for repeating my problem. yes ill try your code this what happen.

hi! @snv thanks for your help

ill create sample picture using photoshop to understand of what i need,

this is the scenario.

  • i purchase 30 items then in my 1st page of my print format will be print 11 items from 1 to 11 and for the 2nd page will be print from 12 to 22 and for the 3rd page from 23 to 30.

sample picture belows.
“1st page”

““2nd page””

““3rd page””

// Code Blocks
{% macro above_items() %}
<div class="page-break" style="border:1px solid #F5FFFA; width:100%; height:963px;">

  <strong>
     <div style="position:relative; margin-top:0px;">
	<img src="/files/RRD LOGO2.jpg" width="65%" height: 25px; style="float:left; position:absolute;">
	<div class="po">
           <p style="font-size:20px; text-align:center;">PURCHASE ORDER</p>
	     <table width="100%">	
	       <tr>
	  	 <th class="sn3">PO No :</td>
  		 <th class="sn3">{{ doc.name }}</td>
	       </tr>
	       <tr>
		 <td class="sn2">Date :</td>
		 <td class="sn2">{{doc.get_formatted("transaction_date")}}</td>
	       </tr>
	     </table>
	</div>
    </div>
  </strong>

  <table style= "width:100%; margin-bottom:10px; margin-top:160px;">
     <tr>
        <td class="sn">SUPPLIER :</td>
        <td class="sn1">{{doc.supplier}}</td>
        <td class="sn"></td>
        <td class="sn"></td>
     </tr>
     <tr>
        <td class="sn">ADDRESS:</td>
        <td class="sn1">{{doc.supplier_address}}</td>
        <td class="sn">TERMS :</td>
        <td class="sn">{{doc.credit_days}}&nbsp;days</td>
     </tr>
  </table>

    <div style="border: 1px solid black; height:405px; width:100%; font-size:12px;">
    <table style= "width:100%; border: 1px solid black;">
       <tr class="tb1">
         <th width="7%">NO</th>
         <th width="45%">ITEM</th>
         <th width="15%">QUANTITY</th>
         <th width="15%">RATE</th>
         <th width="18%">AMOUNT</th>
       </tr>
     </table>
{% endmacro %}

{% macro below_items() %}
</div>
<table height="30px" width="100%">
	<tr style="border:1px solid black;">
	   <th class="total" style="background-color:#DCDCDC; font-size:13px;"><strong>SPECIAL INSTRUCTIONS / REMARKS</strong></td>
	   <td style="width:15%; font-size:12px;">DISCOUNT :</td>
	   <td style="width:20%;  text-align:right; font-size:12px;"> - &nbsp;&nbsp;{{doc.get_formatted("discount_amount",doc)}}</td>
	</tr>

	<tr style="border:1px solid black;">
	   <td class="total">{{doc.remarks}}</td>
	   
	   <th class="grand_total1" width="15%"><strong>TOTAL    :</strong></td>
	   <th class="grand_total2" width="20%"><strong>{{doc.get_formatted("grand_total",doc)}}</strong></td> 
	</tr>
    </table>



    <div>
     <p style="font-weight:bold; font-size:13px;margin-top:5px;">INSTRUCTION TO SUPPLIER:</p>
     <p>1. Please acknowledge immediately receipt on the attach copy.</p>
     <p>2. The acceptance and execution of this order by you implies acceptance of the terms and conditions stated herein.</p>
     <p>3. Please indicate P.O number on your invoice, delivery receipts and packing list.</p>
     <p>4. This purchase order must accompany your invoices and bill of lading upon presentation for payment.</p>
     <br><br>
     <p style="font-weight:bold; font-size:13px;"> P.O. ACKNOWLEDGED BY:</p>
     <br>
     <br>
    </div>



  <div class="feeter">
    <table width="100%">
	<tr>
     	   <td class="signs1">{{doc.creator2}}</td>
     	   <td class="signs"></td>
     	   <td class="signs1">Jimmy Lim</td>
     	   <td class="signs"></td>
     	   <td class="signs1">Joseph Chan</td>
	</tr>
	<tr>
     	   <td class="signs_a">PREPARED BY</td>
     	   <td class="signs"></td>
     	   <td class="signs_a">NOTED BY</td>
     	   <td class="signs"></td>
     	   <td class="signs_a">APPROVED BY</td>
	</tr>
    </table>
  </div>



</div>
{% endmacro %}






// Actual Code

{{ above_items() }}

 <table style="width:100%;">
 {%- for row in doc.items -%}
{% if row.idx % 12 == 0 %}

</table>
{{ below_items() }}
{{ above_items() }}

{% endif %}
<tr>
  <td style="text-align:center; width:7%;">{{ row.idx }}</td>
  <td align="left" width="45%;">{{row.item_name}}</td>
  <td style="text-align:center; width:15%;">{{row.get_formatted("qty")}}&nbsp;{{ row.uom}}</td>
 	  <td style="text-align:center; margin-right:5px; width:15%;">{{row.get_formatted("rate")}}</td>
	  <td style="text-align:center; margin-right:5px; width:18%;">{{row.get_formatted("amount", doc)}}</td>
	</tr>
	{%-endfor-%}	
      </table>
      <p style="text-align:center;">************* Nothing Follows*************</p>

{{ below_items() }}

Hope this helps. :slight_smile:
Edit: I haven’t tested it. If it doesn’t work let me know. Just need to paste the whole code.

4 Likes

hi @snv thankyousomuch! again it works :slight_smile: :smiley:

1 Like