EasyUI Forum
December 14, 2024, 03:57:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combobox select default - HOW  (Read 37716 times)
tlombard
Newbie
*
Posts: 5


View Profile
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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"}]
Logged
tlombard
Newbie
*
Posts: 5


View Profile
« Reply #2 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);

Logged
ryupanqui
Newbie
*
Posts: 44


View Profile Email
« Reply #3 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);
}
Logged
tlombard
Newbie
*
Posts: 5


View Profile
« Reply #4 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);
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!