EasyUI Forum
November 05, 2025, 02:57:01 AM *
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 add a toolbar in a subgrid when expanding a master edatagrid row  (Read 11756 times)
Jeffrey AnnSheila
Newbie
*
Posts: 21


View Profile Email
« on: June 05, 2016, 07:20:59 PM »

Hi bro! I am dealing with an editable subgrid. When I expand or add a row in a master edatagrid, I need a toolbar appear on top of every subgrid when the row of master grid is expanded, so that I can add, save, delete and cancle the row of subgrid. how to do it? Thanks in advance!
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: June 05, 2016, 08:43:03 PM »

To add a toolbar, just need to define the 'toolbar' property when creating the datagrid.
Code:
onExpandRow: function(index,row){
    var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
    ddv.datagrid({
        toolbar:[{
        ...
        }],
        ...
    });
)
Logged
Jeffrey AnnSheila
Newbie
*
Posts: 21


View Profile Email
« Reply #2 on: June 05, 2016, 11:01:57 PM »

HOW TO GET THE NESTED SUBGRID?

I try your code in my page, and modify it like this:
<table id="dg"></table>
<div id="toolbar" hidden="hidden">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">new</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">delete</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">cancel</a>
    </div>
 var conf = {
         options:{
             //...omit the property setting codes here
            url:"xxxxxxxx",
            saveUrl:"xxxxxxxx",
            destroyUrl:"xxxxxxxx",
            updateUrl:"xxxxxxxx",
            edatagrid:true,
            autoUpdateDetail:false,
            columns:[[......]],
             subgrid:{
                options:{
                    rownumbers:true,
                    striped:true,
                    fitColumns:false,
                    nowrap:false,
                    fixed:true,
                    idField:'id',
                    foreignField:'id',
                    url:"xxxxxxxx",
                    saveUrl:"xxxxxxxx",
                    destroyUrl:"xxxxxxxx",
                    updateUrl:"xxxxxxxx",
                    edatagrid:true,
                    autoUpdateDetail:false,
                    toolbar:[{
                      iconCls: 'icon-add',
                      handler: function(){

                                               //HERE IS THE PROBLEM, HOW TO GET THE NESTED SUBGRID? THE "index"  IS UNDEFINED.

                            var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
                            ddv.datagrid('appendRow');
                         }}
                   }],
                   columns:[[......]],
          .....................................
 $(function(){
            $('#dg').datagrid('subgrid', conf);})

I got the firefox debug message :TypeError: $.data(...) is undefined, when the code is running. HOW TO GET THE NESTED SUBGRID?
« Last Edit: June 05, 2016, 11:06:27 PM by Jeffrey AnnSheila » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: June 06, 2016, 01:45:47 AM »

You can call 'getSelfGrid' method to get the self datagrid object. Be sure to download the newest 'datagrid-detailview.js' file from http://www.jeasyui.com/extension/datagridview.php
Code:
toolbar:[{
    iconCls:'icon-add',
    handler:function(){
        var dg = $(this).datagrid('getSelfGrid');
        console.log(dg.datagrid('getRows'));
    }
}]
Logged
Jeffrey AnnSheila
Newbie
*
Posts: 21


View Profile Email
« Reply #4 on: June 06, 2016, 06:10:28 PM »

really thank you Stworthy. Wink Cheesy
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!