EasyUI Forum
April 20, 2024, 07:51:30 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 textbox with default value  (Read 7301 times)
jaimi
Full Member
***
Posts: 119


View Profile
« on: August 30, 2017, 08:58:48 PM »

I want to set a default value on a validatebox within my datagrid at new row. How to?

,{field:'PUA_STATUS',title:'Status',width:080,sortable:'true',editor:{type:'validatebox',options:{required:true}}}
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: August 31, 2017, 07:14:39 AM »

Try this code:
Code:
onBeginEdit: function(index,row){
var ed = $(this).datagrid('getEditor', {index:index,field:'PUA_STATUS'});
$(ed.target).val('default value')
}
Logged
elmorekevin
Newbie
*
Posts: 17


View Profile
« Reply #2 on: November 21, 2018, 09:48:13 AM »

I cannot seem to get this to work. Sorry for reviving this post, thought it would help someone else who finds this. Here is my datagrid code followed by the field definition:
Code:
$(function(){
$('#dg-ap').edatagrid({
fit: true,
fitColumns: true,
idField: 'id',
loadMsg: 'Loading data',
nowrap: true,
pageSize: 50,
pagination: true,
remoteFilter: true,
remoteSort: true,
rownumbers: true,
sortName: 'id',
singleSelect: true,
toolbar: '#toolbar-ap',
updateUrl: 'update_ap.php',
//The following section prevents editing of the AP name, unless it has no name. Use the edit link in the column header instead.
onBeforeEdit: function(val,index,row){
var col = $(this).datagrid('getColumnOption', 'ap_name');
var cell_data = $('#dg-ap').datagrid('getSelected').ap_name;
if (cell_data == null || cell_data==''){
col.editor = {type: 'validatebox', options: {required:true}};
} else {
col.editor = null;
}
//Set AP's active column to 1 ('Y') by default on new save
var ap_active_column = $(this).datagrid('getEditor', {index:index,field:'active'});
console.log(ap_active_column);
$(ap_active_column.target).val(1)

}
});
});
"active" field definition:
Code:
<th field="active" width="45" sortable="true" required="true" 
editor="{type:'combobox',
options:{
valueField: 'id',
textField: 'text',
data:[{
id: '0',
text: 'N'
},{
id: '1',
text: 'Y'
}
]
}
}">Active</th>



When I run this code, I get this in the console:
Code:
Uncaught Syntax error, unrecognized expression: [datagrid-row-index=[object Object]]
k.error @ jquery-1.6.min.js:16
k.filter @ jquery-1.6.min.js:16
k @ jquery-1.6.min.js:16
k @ jquery-1.6.min.js:16
find @ jquery-1.6.min.js:16
getTr @ jquery.easyui.min.js:11094
getTr @ jquery.easyui.min.js:11087
_737 @ jquery.easyui.min.js:10091
_73b @ jquery.easyui.min.js:10103
getEditor @ jquery.easyui.min.js:10726
$.fn.datagrid @ jquery.easyui.min.js:10381
onBeforeEdit @ VM1549:29
onBeforeEdit @ jquery.edatagrid.js:99
_724 @ jquery.easyui.min.js:10028
(anonymous) @ jquery.easyui.min.js:10713
each @ jquery-1.6.min.js:16
each @ jquery-1.6.min.js:16
beginEdit @ jquery.easyui.min.js:10712
$.fn.datagrid @ jquery.easyui.min.js:10381
(anonymous) @ jquery.edatagrid.js:302
each @ jquery-1.6.min.js:16
each @ jquery-1.6.min.js:16
editRow @ jquery.edatagrid.js:287
$.fn.edatagrid @ jquery.edatagrid.js:233
onDblClickCell @ jquery.edatagrid.js:70
_686 @ jquery.easyui.min.js:9304
handle @ jquery-1.6.min.js:16
k @ jquery-1.6.min.js:16

So I figured it had to do with having extra stuff already in the onBeforeEdit definition. When I remove the "val" from the function, and comment out the ap_name section (so it looks like the example in the previous post), then I get this in the console (this first null line is due to console.log(ap_active_column)):
Code:
null 
VM1306:31 Uncaught TypeError: Cannot read property 'target' of null
    at HTMLTableElement.onBeforeEdit (eval at <anonymous> (jquery-1.6.min.js:16), <anonymous>:31:23)
    at HTMLTableElement.onBeforeEdit (jquery.edatagrid.js:99)
    at _724 (jquery.easyui.min.js:10028)
    at HTMLTableElement.<anonymous> (jquery.easyui.min.js:10713)
    at Function.each (jquery-1.6.min.js:16)
    at init.each (jquery-1.6.min.js:16)
    at Object.beginEdit (jquery.easyui.min.js:10712)
    at init.$.fn.datagrid (jquery.easyui.min.js:10381)
    at HTMLTableElement.<anonymous> (jquery.edatagrid.js:302)
    at Function.each (jquery-1.6.min.js:16)

What might I be doing wrong here?
Thanks!

« Last Edit: November 21, 2018, 09:51:19 AM by elmorekevin » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: November 21, 2018, 06:24:22 PM »

You used the wrong parameters in the 'onBeforeEdit' function. Please notice that the first and second parameters in the 'onBeforeEdit' function are 'index' and 'row'.
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!