EasyUI Forum
May 09, 2024, 08:01:19 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: datagrid('getData') runs before data is loaded. [Resolved]  (Read 8744 times)
dies_felices
Newbie
*
Posts: 24


View Profile
« on: August 06, 2015, 01:12:44 PM »

Hi,

I have some code like this:

Code:
var dgrid = $('#new_table');
    dgrid.datagrid({
        title: 'Datagrid',
        singleSelect: true,
        width: '80%',
        url: cloud.example.php?highlander="Doogle",
        columns:[[
            {field:'itemid',title:'Item ID',width:'15%',
                editor:{
                    type:'combobox',
                    options:{
                        valueField:'Ind',
                        textField:'Vol',
                        data: items,
                        required: true
                    }
                }
            },
            {field:'productid',title:'Product',width:'15%',align:'center',editor:'text'}
        ]]
    });

 dgrid.datagrid('enableCellEditing').datagrid('gotoCell', {
                index: 0,
                field: 'productid'
            });

Previously, when giving examples static data has been used.  This allowed for an easy to use for-loop to create the data structure for the items in the combobox.

Now data is retrieved from the server so a new method to populate the combox data structure is needed.

So I tried this:

Code:
var AllData
dgrid.datagrig({onLoad:function(){AllData = dgrid.datagrid('getData');
alert(values : ' + JSON.stringify(AllData))

This comes up empty.  Then only after the alert is dismissed does the datagrid populate.  Additionally, I need to add a new value to this when I call the new row function.  If I'm barking up the wrong tree please let me know?

The end game for the combobox value is to be able to swap the values between two rows.  So when edited a new value is selected - updated and the record which had the new value gets the old value and is updated.

Also this relates tangentially to the problem of storing edited values back on the server.  Relating the changed cell value to the field and record id.  I hope I'm not pushing my luck...

I apologise for dropping a great mess like this all in one question.  It is my hope that if you're aware what I intend to achieve this simplify things.
« Last Edit: August 09, 2015, 10:38:57 AM by dies_felices » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: August 06, 2015, 05:42:38 PM »

When the data is loaded into datagrid successfully, the 'onLoadSuccess' event fires. Please try this code instead.
Code:
var AllData
dgrid.datagrid({
onLoadSuccess:function(){
AllData = dgrid.datagrid('getData');
alert(values : ' + JSON.stringify(AllData))
}
});
Logged
dies_felices
Newbie
*
Posts: 24


View Profile
« Reply #2 on: August 09, 2015, 10:38:26 AM »

Hi,

Thank you, that has worked splendidly!
Logged
karogel
Newbie
*
Posts: 28


View Profile
« Reply #3 on: July 28, 2016, 08:02:18 PM »

sir how to pass the stringtify data to server
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!