EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Alfred on November 28, 2016, 12:57:52 AM



Title: How to create datagrid with new data on opening a window
Post by: Alfred on November 28, 2016, 12:57:52 AM
I have tried the following code to open a window using javascript:

Code:
<div id="expwin" class="easyui-window">
   <table id="expdg"></table>
</div>
Code:
$('#expwin').window({'onOpen',
      function(){
     var t = $('#expdg').datagrid({
      url:'get_expiring.php',      
      toolbar: '#exptoolbar',
      pagination:true,
        columns:[[
            {field:'drugname',title:'name',width:100},
            {field:'batchno',title:'batch',width:100},
            {field:'pack',title:'package',width:100},
            {field:'qps',title:'qpur',width:100},
            {field:'qs',title:'qsold',width:100},
            {field:'qout',title:'qout',width:100},
            {field:'entrydate',title:'endate',width:100},
            {field:'mdate',title:'mdate',width:100},
            {field:'expdate',title:'edate',width:100,align:'right'}
        ]]
    });
      return t;
}
});

To open the window:
Code:
<div class="t-list" onclick="$('#expwin').window('open')">test</div>
The problem is that there is no error in the console, and this does not populate the datagrid table as well. I want to populate the datagrid with data from get_expiring.php when I click test. How can I achieve this?


Title: Re: How to create datagrid with new data on opening a window
Post by: jarry on November 28, 2016, 02:22:17 AM
Please call this code instead.
Code:
$(function(){
$('#expwin').window({
onOpen: function(){
$('#expdg').datagrid({
url: 'get_expiring.php',
//...
})
}
})
})


Title: Re: How to create datagrid with new data on opening a window
Post by: Alfred on November 28, 2016, 09:05:15 AM
Thanks very much, this works.