EasyUI Forum
October 03, 2025, 10:34:58 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 Append getting data from previous row [solved]  (Read 16653 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: May 14, 2013, 09:05:17 PM »

Hi;

For certain columns, I need to get the column.value from the previous row when appending a new row.

Any suggestions on how this can be done from within data-options > columns > field ?

Thanks
« Last Edit: May 16, 2013, 04:53:59 PM by devnull » Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 14, 2013, 11:34:44 PM »

Call 'getColumnOption' method to get a specified column's option which contains your customized value.

Code:
<th data-options="field:'name',value:'abc',...">
  ...
</th>
Code:
var col = $('#dg').datagrid('getColumnOption', 'name');
var value = col.value;  // get the value defined in 'data-options'
alert(value);
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 on: May 15, 2013, 12:18:04 AM »

Thanks so much for helping, appreciate your patience !

I didn't explain very weel, is it possible to do this using code inside the column definition, maybe by using a custom editor something like this:

Code:
{field:'SEQUENCE_NO',title:'Sequence',editor: {type:text, function(){return $(this).datagrid('getRows')[index -1].value;}} },

I want to pull the value from the previous row and have the option to overwrite the value.
« Last Edit: May 15, 2013, 04:03:23 AM by devnull » Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: May 15, 2013, 08:12:20 PM »

Don't clearly know what you want to do. If want to set the column's customized value when end editing a row, try the code below:
Code:
// extend your custom text editor
$.extend($.fn.datagrid.defaults.editors,{
    customtext:{
        init: function(container, options){ 
            var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container);
    input.data('customtext',{options:options});
            return input; 
        }, 
        getValue: function(target){
var value = $(target).val();
var opts = $(target).data('customtext').options;
if (opts.callback){
opts.callback.call(target, value);
}
            return value; 
        }, 
        setValue: function(target, value){ 
            $(target).val(value);
        }, 
        resize: function(target, width){ 
            $(target)._outerWidth(width);
        } 
    }
});

Apply the 'customtext' editor to a column.
Code:
<th data-options="field:'attr1',width:250,editor:{
type:'customtext',
options:{
callback:function(value){
var col = $('#dg').datagrid('getColumnOption','attr1');
col.value = value;
}
}
}">Attribute</th>
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #4 on: May 15, 2013, 10:04:45 PM »

Hi;

See attached screen shot.

When a new row is inserted, I want to get the "Seq No" value from the previous row and add 10 to it.

The previous Seq No was 60, and so this row would default to 70 (previous + 10), however the user could override this default if they wanted to.

But the problem is that I need to be able to do this from the table column definition and not by using a custom on-insert function.
Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: May 16, 2013, 12:30:07 AM »

Try the code below:
Code:
var dg = $('#dg');
var rows = dg.datagrid('getRows');
var lastIndex = rows.length - 1;
dg.datagrid('appendRow',{seq: rows[lastIndex].seq+10});
dg.datagrid('selectRow', lastIndex+1).datagrid('beginEdit', lastIndex+1);
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #6 on: May 16, 2013, 12:47:24 AM »

Thanks, but I needed for this to be done inside the datagrid column definition, this now works:

Code:
$.extend($.fn.datagrid.defaults.editors, {  
    xtext: { 
        init: function(container, options){ 
            var input = $('<input type="text" class="datagrid-editable-input">').appendTo(container); 
            input.data('xtext',{options:options});
            return input; 
        },
        getValue: function(target){ 
            return $(target).val(); 
        }, 
        setValue: function(target, value){ 
            var opts = $(target).data('xtext').options;
            if (opts.callback) value = opts.callback.call(target, value);
            $(target).val(value); 
        }

}});

Code:
editor:{
type:'xtext',
options:{ callback: function(target, value) {
var lrow = $('#t_dg_op').datagrid('getRows').length - 2;
return parseInt($('#t_dg_op').datagrid('getRows')[lrow].SEQUENCE_NO)+10;
}}
}},
Logged

-- Licensed User --
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!