zac
zac

Reputation: 4898

How to reload grid data based on combo box selection?

I have a combo box and grid from easyui and I need to make the grid data change to display detail data when the current selected item in the combo box change.

Here is the code of the combo box:

<input class="easyui-combobox" name="wg_id" id="wg_id" value="1"
    data-options="
        url:'pages/get_work_groups.php',
        method:'get',
        valueField:'work_group_id',
        textField:'work_group',
        panelHeight:'auto',
        onSelect: function(rec){
          $.post('pages/get_locations.php', {wg_id: '2'});

        }

">

And the get_locations.php code:

include '../conn.php';

$wg_id = 1;
if (isset($_REQUEST['wg_id'])) {
    $wg_id = $_REQUEST['wg_id'];
}

$q = $conn->prepare("select * from locations where work_group_id = :wg_id");
$q->bindValue(':wg_id', $wg_id);
$q->execute();

$result = $q->fetchAll();
echo json_encode($result);

The json data returned from get_locations.php is correct but how I can make the grid reload to display these data ?

Upvotes: 0

Views: 2155

Answers (1)

Saigitha Vijay
Saigitha Vijay

Reputation: 466

Use the below code,

 <input class="easyui-combobox" name="wg_id" id="wg_id" value="1"
        data-options="url:'pages/get_work_groups.php',
            method:'get',
            valueField:'work_group_id',
            textField:'work_group',
            panelHeight:'auto',
            onSelect: function(rec){
              $('#dg').datagrid({url:'pages/get_locations.php'});
            }
    ">

Upvotes: 1

Related Questions