EasyUI Forum
April 19, 2024, 04:33:23 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: Datagrid editor combobox after updateRow  (Read 1115 times)
Wojak
Newbie
*
Posts: 48


View Profile Email
« 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
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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 });
});
Logged
Wojak
Newbie
*
Posts: 48


View Profile Email
« Reply #2 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
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!