EasyUI Forum
September 16, 2025, 07:46:04 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: How to reload data to dependant combobox inside a grid ?  (Read 12685 times)
wel
Newbie
*
Posts: 30


View Profile Email
« on: January 09, 2016, 12:03:36 PM »

I have a grid that has two dependant comboboxes and I am trying to make the second combobox reload its data when the first one change selection so I wrote this code:

Code:
<th data-options="field:'work_group_id',width:20,
                  formatter:function(value,row){
                       return row.work_group;
                  },
                  editor:{
                      type:'combobox',
                       options:{
                       valueField:'work_group_id',
                       textField:'work_group',
                       method:'get',
                       url:'pages/work_groups.php',
                       required:true,
                       onSelect: function(rec){
                           var loc_ed = $('#dg').datagrid('getEditor', {
                             index: 1,
                             field:'location_id'
                          });
                          var url = 'pages/get_locations.php';
                          $(loc_ed.target).combobox('reload', url);

                     }
                 }
            }

      ">Work Group
</th>

The problem I get JS error that loc_ed is null in the line $(loc_ed.target).combobox('reload', url); !! please advise
« Last Edit: January 09, 2016, 07:42:06 PM by wel » Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: January 10, 2016, 04:58:35 PM »

Please use 'onBeginEdit' event to get the editors and bind their dependent events. This tutorial shows how to create two dependent editors.

http://www.jeasyui.com/tutorial/datagrid/datagrid15.php
Logged
wel
Newbie
*
Posts: 30


View Profile Email
« Reply #2 on: January 10, 2016, 07:55:39 PM »

I have a problem, I tried to write the code like in the example but using onSelect event but the first combobox text is disappear when I start edit and change selection, also the data for the first combobox is loaded twice why is that ?

Here are the code I used:


Code:
$(function(){
            $('#dg').edatagrid({
                url: 'pages/get_jobmsg.php',
                saveUrl: 'pages/save_jobmsg.php',
                updateUrl: 'pages/update_jobmsg.php',
                destroyUrl: 'pages/destroy_jobmsg.php',
                onBeginEdit:function(index,row){
                    var editors = $(this).datagrid('getEditors', index);

                    var ed_wg  = $(editors[2].target);
                    var ed_loc = $(editors[3].target);

                    ed_wg.combobox({
                        onSelect: function(rec){
                          var url = 'pages/get_locations.php';
                          ed_loc.combobox('reload', url);
                      }
                    });

                },

                onEndEdit: function(index,row){
                    var wg_ed = $(this).datagrid('getEditor', {
                        index:index,
                        field:'work_group_id'
                    });
                    row.work_group = $(wg_ed.target).combobox('getText');

                }
            });
        });

And the columns

Code:
<th data-options="field:'work_group_id',width:20,
                                    formatter:function(value,row){
                                        return row.work_group;
                                    },
                                    editor:{
                                        type:'combobox',
                                        options:{
                                            valueField:'work_group_id',
                                            textField:'work_group',
                                            method:'get',
                                            url:'pages/work_groups.php',
                                            required:true

                                        }
                                    }">Work Group
                                </th>

                                <th data-options="field:'location_id',width:20,
                                    formatter:function(value,row){
                                        return row.location_name;
                                    },
                                    editor:{
                                        type:'combobox',
                                        options:{
                                            valueField:'location_id',
                                            textField:'location_name',
                                            required:true
                                        }
                                    }">Location
                                </th>


And here is a video demonstrate the problem, please advise

https://vid.me/JUex
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #3 on: January 11, 2016, 01:33:26 AM »

Please try this code instead.
Code:
onBeginEdit:function(index,row){
    var editors = $(this).datagrid('getEditors', index);

    var ed_wg  = $(editors[2].target);
    var ed_loc = $(editors[3].target);

    ed_wg.combobox('options').onSelect = function(rec){
        var url = 'pages/get_locations.php';
        ed_loc.combobox('reload', url);   
    }
},
Logged
wel
Newbie
*
Posts: 30


View Profile Email
« Reply #4 on: January 11, 2016, 10:14:58 AM »

Many thanks Jarry you saved my day.
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!