EasyUI Forum
May 21, 2024, 06:06:04 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 editable  (Read 5602 times)
bakkers
Newbie
*
Posts: 21


View Profile Email
« on: March 03, 2016, 12:33:08 AM »

Hello

I have a datagrid with two fields, for this example lets call them A and B.

Row B is always editable so i have made it this way

<th data-options="field:'B',editor:'textbox'" width="100">B</th>

but A should only be editable when i append a new row, so i need to change A to editable from my append function

 function append(){
            if (endEditing()){
                $('#kundeData').datagrid('appendRow',{status:'P'});
                editIndex = $('#kundeData').datagrid('getRows').length-1;
                $('#kundeData').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex);
            }
        }

How do i do that?

Regards
Bakkers
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 03, 2016, 08:19:53 AM »

Here is the solution to solve this question:

1. When appending a new row, set a 'isNewRow' property indicating this is a new added row.
Code:
$('#dg').datagrid('appendRow',{status:'P',isNewRow:true});

2. Use the 'onBeforeEdit' event to prevent from editing the 'A' field on the old rows.
Code:
$('#dg').datagrid({
onBeforeEdit: function(index,row){
var col = $(this).datagrid('getColumnOption','A');
if (row.isNewRow){
col.editor = 'textbox';
} else {
col.editor = null;
}
},
onAfterEdit: function(index,row){
row.isNewRow = false;
}
})
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!