Here come the code, let say we have an multiple select name "option" and here is the code to make the multiselec auto select the first value in the first loaded. As you may see in the defaultParamValues() function, we try to connect to database, query all possible options and return the selected one.
As you may notice the function requestDataSending()
at the end. This function force the datapipe start to query and push data from the source. That why after this function, we can get data from $this->dataStore("options")
.
Here come the code:
protected function defaultParamValues()
{
$this->src("mysource")
->query("SELECT name,value FROM tbl_options")
->pipe($this->dataStore("options"))
->requestDataSending();
$data = $this->dataStore("options")->data();
//Now you have $data containing list of all possible values, you can set default selection
//base on $data.
return array(
"option"=>array($data[0]["value"]), // Select first item.
);
}
protected function bindParamsToInputs()
{
return array(
"option",
);
}