EasyUI Forum

General Category => General Discussion => Topic started by: tlombard on December 23, 2013, 07:38:58 AM



Title: Combobox select default - HOW
Post by: tlombard on December 23, 2013, 07:38:58 AM
I have a combobox:

Code:
<input id="unit_FIELD" class="easyui-combobox"
        name="unit_FIELD" data-options=" url:'get_units.php',
valueField:'unitID',
textField:'unitID'
        ">

I'm populating the ComboBox just fine with the get_units.php code.

Code:
[{"unitID":"ALL"},{"unitID":"001"},{"unitID":"002"},{"unitID":"003"},{"unitID":"004"}]

I need to be able to have a default selected...How do I select the first item in the combox by default WHEN the combobox is popluated from a Database?

-Tom


Title: Re: Combobox select default - HOW
Post by: stworthy on December 24, 2013, 05:54:10 PM
A data item with 'selected' set to true will be selected by combobox. So, add 'selected' property to what item you want to be selected.

Code:
[{"unitID":"ALL","selected":true},{"unitID":"001"},{"unitID":"002"},{"unitID":"003"},{"unitID":"004"}]


Title: Re: Combobox select default - HOW
Post by: tlombard on December 25, 2013, 09:31:06 AM
I have not been able to add the ,"selected":true into that array push item
Code:
$items = array();

while($row = mysql_fetch_object($rs)){
     // PSEDUO Code IF 'All' THEN
     array_push($items, $row + ',"selected":true');  [b]///I'M STUCK HERE...HOW TO CONCAT INTO THIS ITEM[/b]
     //ELSE
    array_push($items, $row);
   }
   
$result = $items;
echo json_encode ($result);



Title: Re: Combobox select default - HOW
Post by: ryupanqui on December 26, 2013, 09:15:53 AM
try this

Code:
$items = array();

while($row = mysql_fetch_object($rs)){
     // PSEDUO Code IF 'All' THEN
     $row->selected = true;
     //END IF

    array_push($items, $row);
}


Title: Re: Combobox select default - HOW
Post by: tlombard on December 26, 2013, 10:53:12 AM
SOLVED...thanks 'ryupanqul'

Code:
$rs = mysql_query("SELECT unitID FROM unit ORDER BY case when unitID = 'All' THEN 0 ELSE 1 END, unitID");
$items = array();
while($row = mysql_fetch_object($rs)){

if ($row->unitID == 'ALL') {
$row->selected = true;
}

array_push($items, $row);
}

$result = $items;
echo json_encode ($result);