EasyUI Forum
April 29, 2024, 04:03:15 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: onLoadSuccess for datagrid firing multiple times  (Read 14971 times)
chrisphayao
Newbie
*
Posts: 1


View Profile Email
« on: September 16, 2013, 04:39:06 AM »

Hello,

I don't know whats the problem but when I declare an onLoadSuccess function in my datagrid definition, this function is called 4 times, thereby making the whole idea useless.
I wanted to show an alert and open the detailview input box for the first row of a table if there are no data yet. The alert box opens 4 times until i can finally input the data.
My code:
                         $('#dg_exp').datagrid({
            url: "get_experiments.php",
            toolbar: '#toolbar',
            nowrap: false,  // more than 1 line per row allowed
            idField: 'taskid', 
            rownumbers: true,
            fitColumns:true, // no horizontal scrolling
            pagination:true, // show refresh footer
            singleSelect: true,
            onLoadSuccess: inputexp,  // function inputexp to open input mask
            columns:[[ 
               {field:'taskid',title:'',hidden:'true'},  // hidden col. with task id
               {field:'title',title:'Title',width:100},
               {field:'detail',title:'Details',width:150},   
               {field:'lit',title:'Literature',width:150},   
               {field:'datum',title:'Startdate',width:60},
               {field:'nsteps',title:'# steps',width:40}
            ]]
         });   

                  function inputexp(data) {  // call from onLoadSuccess in exp_dg
         //
         loadSuccess = false;
         currentid = data.rows[0].taskid;
         if (currentid !='N') return;
         else {  // no exp. yet -> fill row with index 0
            // this messager box opens multiple times : !!!   Sad Sad Sad
                                $.messager.alert('My Experiment','Please fill your first experiment','info');
            row = $(this).datagrid('getRows')[0];
            row.isNewRecord = true;  // to make 'insert' action
            $('#dg_exp').datagrid('expandRow', 0);
            $('#dg_exp').datagrid('selectRow', 0);
            return;
         }
      }

Any ideas ? 

Thanks very much in advance,

Chris
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 16, 2013, 06:37:48 AM »

If you have class="easyui-datagrid" attribute in <table> markup and call $('#dg_exp').datagrid({...}) again, the datagrid will be created multiple times. Please remove class="easyui-datagrid" attribute from <table> markup to prevent from this issue.
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!