Skip to content

Do something beyond standard data source

Ks Tan edited this page Sep 6, 2019 · 17 revisions
  1. Using dynamic sql, which is not exists in jrxml file:
$sql="SELECT * FROM table1";
$PHPJasperXML->load_xml_file('file1.jrxml'); 
$PHPJasperXML->sql = $sql;  
  1. Using flexible data using array:
$data=[
    ["id"=>1,"name"=>"John","age"=>30],
    ["id"=>2,"name"=>"Mr Lee","age"=>23],
];
$PHPJasperXML->load_xml_file('file1.jrxml'); 
$PHPJasperXML->setData($data);
  1. Use php variable/function instead of jasper report rules In text field, usually you define something as $F{column1}, that is follow Jaspersoft standard. In fact, it is very restricted and lot of time insufficient for complex case. We can do something as when necessary:
$mycompanyname="Sim It Sdn Bhd";
function mytime(){
 return date('Y-m-d');
}
...load phpjasperxml...

then, in jrxml's text field. you can simply pass php function or variable such as $mycompanyname or mytime(), str_replace('Sdn Bhd','S/B',$mycompanyname). It is very flexible but use this in your own risk,

  1. Access data all data easily, across all rows. Sometimes, we may have requirement to access next row record or previous row record during we define "Print When Expression". No matter we wish to show the value in text field, or use in "Print When Expression". We can by pass Jasper Report rules via direct access into php variable in our object.
    Example,
    a. I wish to show first record column1: $this->arraysqltable[0]["column1"]
    b. I wish to get last row column1 record: $this->arraysqltable[($this->global_pointer-1)]["column1"]
    c. Dont display this column, by set this at print when expression:
    $this->arraysqltable[($this->global_pointer-1)]["column1"] !=$this->arraysqltable[($this->global_pointer)]["column1"]
Clone this wiki locally