EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: dies_felices on August 06, 2015, 01:12:44 PM



Title: datagrid('getData') runs before data is loaded. [Resolved]
Post by: dies_felices 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.


Title: Re: datagrid('getData') runs before data is loaded.
Post by: stworthy 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))
}
});


Title: Re: datagrid('getData') runs before data is loaded.
Post by: dies_felices on August 09, 2015, 10:38:26 AM
Hi,

Thank you, that has worked splendidly!


Title: Re: datagrid('getData') runs before data is loaded. [Resolved]
Post by: karogel on July 28, 2016, 08:02:18 PM
sir how to pass the stringtify data to server