KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Select box list binding problem #1222

Open Sowmya opened this topic on on Dec 19, 2019 - 7 comments

Sowmya commented on Dec 19, 2019

Dear KoolReport team,

I am trying to bind data to the select box. But it displays empty. Here is my code. Please let me know where I done mistake.

SelectList.php(Controller)

class SelectList extends CI_Controller
{
	 public function index()
   	{
   		$this->load->helper('url');
   		$this->load->database('MainiDM');
   		
   		include APPPATH."reports\SelectList_Ex.php";

   		$report = new SelectList_Ex;
                 $report->run()->render();
   	}
}

SelectList_Ex.php(reports)

class SelectList_Ex extends \koolreport\KoolReport
{
	
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
   
    function defaultParamValues()
    {
        return array(
            "Customer"=>null,
        );
    }
    function bindParamsToInputs()
    {
    	return array(
    		"Customer"
    	);
    }

    public function settings()
	{
		return array(
			
            "dataSources"=>array(
                "select"=>array(
                    "connectionString"=>" ------"
                )
            )
        );
	}

	public function setup()
    {
        $this->src('select')
        ->query("SELECT DISTINCT CustomerName from EnquiryDataView ORDER BY CustomerName")
        ->pipe($this->dataStore("customers"));
    }

SelectList_Ex.view.php

<?php
 use \koolreport\inputs\Select;

 $CustomerName = "";
 $this->dataStore("customers")->popStart();
 while($row=$this->dataStore("customers")->pop())
 {
 	$CustomerName = $row["CustomerName"];

 	echo $CustomerName;
 }
?>

<form method="post">
	<?php
		Select::create(array(
			"name" => "Customer", 
			"datastore"=>$this->dataStore('customers'),
			"dataBind"=>array(
				"text"=>"CustomerName",
			    "value"=>"CustomerName"),
			"attributes"=>array(
                        "class"=>"form-control"),
                        ));
        ?>
        <div class="form-group">
                <button class="btn btn-primary">Submit</button>
            </div>
</form>

By printing customername with echo statement, I got the data as above, but I want to bind this data to SelectBox.

Please Please give me the solution as early as possible.

Sowmya commented on Dec 20, 2019

Hello Support team is there?

David Winterburn commented on Dec 20, 2019

Please try:

    function defaultParamValues()
    {
        return array(
            "Customer"=>"",
        );
    }

Let us know if it helps. Thanks!

Sowmya commented on Dec 20, 2019

Thank you for your reply. But that solution is not worked.

David Winterburn commented on Dec 20, 2019

Would you please inspect the select element (right mouse click on the element -> Inspect) and post its html content here for us to check? Thanks!

Sowmya commented on Dec 20, 2019

<select id="Customer" name="Customer" class="form-control"> </select>

David Winterburn commented on Dec 20, 2019

Ok, I found the bug:

                    Select::create(array(
			"name" => "Customer", 
			"datastore"=>$this->dataStore('customers'), // use "dataStore" here instead of "datastore"

In PHP, array key is case sensitive which means that $arr["dataStore"] is different from $arr["datastore"]. Please be careful next time. I would advise you copy and modify our example, not retyping.

Sowmya commented on Dec 20, 2019

Yes Sir. It worked. Thank You so much....

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Inputs