I've set a select2 widget in dashboard like this example but with multiple(true) and I don't get the default values. Also it doesn't work if i use MultiSelect instead of Select2 Can you help?
Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
I've set a select2 widget in dashboard like this example but with multiple(true) and I don't get the default values. Also it doesn't work if i use MultiSelect instead of Select2 Can you help?
Probably you have to set the default value of inputs be it TextBox, Select2, BSelect, etc in the report class file like this:
class Report extends \koolreport\KoolReport
{
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
protected function defaultParamValues()
{
return array(
"textBox"=>"KoolReport is great",
"singleSelect2" => 'Enaco Distributors', // single select value should be a string or number
"multipleSelect2" => ['Enaco Distributors'], // multiple select value should be an array
...
);
}
Ah, sorry I didn't notice that you mentioned Select2 input in a KoolReport Dashboard instead of an individual report. In that case you can set Select2's default value directly like this:
class MultipleSelect2Demo extends Select2
{
protected function onCreated()
{
$this
->multiple(true)
->defaultValue(['Australia', 'Austria']);
}
You can see image and code below.
Code
<?php
namespace myforder;
use \koolreport\dashboard\inputs\Select2;
use \koolreport\dashboard\fields\Number;
use \koolreport\dashboard\fields\Text;
class mySelectbox extends Select2
{
protected function onInit()
{
$this
->defaultOption(['ABC'])
->cssStyle('margin-left:10px')
->cssClass('form-control')
->multiple(true) ;
}
//Provide datasource
protected function dataSource()
{
return \xxx\myDB::table("customers")
->select("customerName")
->orderBy("customerName") ;
}
//Provide list of fields to act as value and text for MultiSelect
protected function fields()
{
return [
Text::create("customerName")
];
}
//Update when user select values
protected function actionChange($request, $response)
{
$this->sibling("ChartTest3")->update();
}
}
In Dashboard's Select2, ->defaultOption() is not the same as ->defaultValue() and function onInit() is different from function onCreated(). Pls try this exact method with your Dashboard's Select2:
protected function onCreated()
{
$this
->multiple(true)
->defaultValue(['ABC']);
}
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo