EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Wojak on October 28, 2022, 07:28:01 AM



Title: Datagrid editor combobox after updateRow
Post by: Wojak on October 28, 2022, 07:28:01 AM
Hi
I have a problem with datagrid while using updateRow, the example below is my datagrid that im using
Code:
$('#example-dg').datagrid({
        columns: [[
            { field: 'waluta', title: 'Waluta', width: '80px', align: 'center', editor: { type: 'combobox', options: { textField: 'nazwa_waluta', valueField: 'waluta', url: 'link/to/query.php' } }, formatter: function (value, row, index) {
                return row.nazwa_waluta;
            }},
        ]],
        rownumbers: 'true',
        showFooter: 'true',
        singleSelect: 'true',
        idField: 'id',
        onEndEdit: function (index, row) {
            const ed = $(this).datagrid('getEditor', {
                index: index,
                field: 'waluta'
            });
            row.nazwa_waluta = $(ed.target).combobox('getText');
    });

and this is the combobox with other onchange that im using to massUpdate the field "waluta"

Code:
$('#example-combobox').combobox({
        onChange: function(newValue, oldValue) {
            const dg = $('#example-dg');
            if (newValue != '' && !isNaN(newValue)) {
                const rows = dg.datagrid('getRows');
                $.each(rows, function (i, e) {
                    e.waluta = parseInt(newValue);
                    dg.datagrid('updateRow', { index: i, row: e });
                });
            }
        }
    });

If i change the value in "$('#example-combobox')", datagrid is not refreshing with new data but if i beginEdit the new data is shown in combobox


Title: Re: Datagrid editor combobox after updateRow
Post by: jarry on October 31, 2022, 08:10:38 PM
You should set the row's 'nazwa_waluta' value because the datagrid's 'formatter' is defined to display this value.
Code:
const comboText = $(this).combobox('getText');
const rows = dg.datagrid('getRows');
$.each(rows, function (i, e) {
    e.waluta = parseInt(newValue);
    e.nazwa_waluta = comboText;
    dg.datagrid('updateRow', { index: i, row: e });
});


Title: Re: Datagrid editor combobox after updateRow
Post by: Wojak on November 02, 2022, 12:40:51 AM
Thanks for helping, i changed it as follow
Code:
$('#example-combobox').combobox({
        onChange: function(newValue, oldValue) {
            const dg = $('#example-dg');
            const comboText = $(this).combobox('getText');
            if (newValue != '' && !isNaN(newValue)) {
                const rows = dg.datagrid('getRows');
                $.each(rows, function (i, e) {
                    e.waluta = parseInt(newValue);
                    e.nazwa_waluta = comboText;
                    dg.datagrid('updateRow', { index: i, row: e });
                    dg.datagrid('refreshRow', i);
                });
            }
        }
    });

Because i need that 'waluta' value too