EasyUI Forum

General Category => General Discussion => Topic started by: Jonny on April 07, 2015, 01:33:45 AM



Title: How to define each TAB's ONCLOSE with different scenario?
Post by: Jonny on April 07, 2015, 01:33:45 AM
Dear ALL,

Is there any syntax to ADD TAB with their own ONCLOSE behavior ( scenario ) ?
Everytime adding Tab, I create a temporary table in MySQL…
So… when closing TAB, I want to delete that temporary Table
This is my code:
function addTabxxx(title, url, tmptable ){
    if ($('#tablgn').tabs('exists', title))
            { $('#tablgn').tabs('select', title); }
   else {
            var vtemp = tmptable;
            var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;">  </iframe>';
            $('#tablgn').tabs('add',{
                        title:title,
                        content: content,
                        bodyCls:'noscroll',
                        onClose: function(title,index){
                                    $.ajax({url : 'DLGN_KILLTMP.PHP',
                                                type : 'get',
                                                dataType : 'json',
                                                data : { temporary : vtemp },
                                                success : function(respond){ alert('Hello temporary table KILLED'); },
                                                error : function(a,b,c){alert('Error : '+b);}
                                                });       
                                                },
                          closable:true
                          });
            }
}         
This coding did not work… I don’t see any error in my parameter…
Maybe this syntax not acceptable….
If you know the correct Syntax.... Please guide me...
Thank you...

Regards,
JONNY


Title: Re: How to define each TAB's ONCLOSE with different scenario?
Post by: stworthy on April 07, 2015, 01:58:32 AM
When adding a tab panel, attach your 'tmptable' value to the panel options.
Code:
$('#tablgn').tabs('add',{
title:title,
closable:true,
tmptable:tmptable
})

When closing a tab panel, the 'onBeforeClose' event fires, you can retrieve the attached 'tmptable' value on this event and then make an ajax request to your remote server.
Code:
$('#tablgn').tabs({
onBeforeClose: function(title,index){
var p = $(this).tabs('getTab', index);
var tmptable = p.panel('options').tmptable;
}
})


Title: Re: How to define each TAB's ONCLOSE with different scenario?
Post by: Jonny on April 07, 2015, 02:28:44 AM
Such a perfect solution for my case...
I never imagine easyui-tabs allow user to put any variable ('tmptable') when adding TAB....

I am spending a whole day seeking solution....... solved in a minute by you...
Thank you stworthy...