|
Title: can not set the default value of textbox and checkbox in the new added row Post by: Jeffrey AnnSheila on June 15, 2016, 05:36:50 AM I want to set the default value of textbox and the default selected option of checkbox in a new added row, but the default values don't show, I don't know why. My codes are like below:
<html> <head> <meta charset=utf-8 /> <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css"> <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css"> <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.min.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.edatagrid.js"></script> </head> <body> <table id="dg"></table> <script type="text/javascript"> var conf = { options:{ fitColumns:true, autoUpdateDetail:false, toolbar : [ { iconCls : 'icon-add', text : 'new', handler : function() { $('#dg').edatagrid('addRow'); } }, '-', { iconCls : 'icon-remove', text : 'del', handler : function() { $(this).datagrid('getSelfGrid').edatagrid('destroyRow'); } }, '-', { iconCls : 'icon-save', text : 'save', handler : function() { $(this).datagrid('getSelfGrid').edatagrid('saveRow'); } }, '-', { iconCls : 'icon-undo', text : 'cancel', handler : function() { $(this).datagrid('getSelfGrid').edatagrid('cancelRow'); } } ], columns:[[ {field:'company',title:'Company Name',width:200,editor: {type:'textbox',options:{value:"xxxxxxxxxxx"}}}, {field:'contact',title:'Contact Name',width:200,editor : {type:'combobox',options:{ data : [ { label : 'A', value : 'a' }, { label : 'B', value : 'b', selected :true } , { label : 'C', value : 'c' } ], panelHeight : 'auto', valueField : 'value', textField : 'label' }}}, {field:'country',title:'Country',width:200,editor : 'text'} ]], data:[ {company:'Speed Info',contact:'Minna John',country:'Sweden'} ] }, subgrid:{ options:{ fitColumns:true, foreignField:'companyid', columns:[[ {field:'orderdate',title:'Order Date',width:200}, {field:'shippeddate',title:'Shipped Date',width:200}, {field:'freight',title:'Freight',width:200} ]], data:[ {orderdate:'08/23/2012',shippeddate:'12/25/2012',freight:9734}, {orderdate:'08/23/2012',shippeddate:'12/25/2012',freight:9734}, {orderdate:'08/23/2012',shippeddate:'12/25/2012',freight:9734} ] }, subgrid:{ options:{ fitColumns:true, foreignField:'orderid', columns:[[ {field:'price',title:'Unit Price',width:200,align:'right'}, {field:'quantity',title:'Quantity',width:200,align:'right'}, {field:'discount',title:'Discount',width:200,align:'right',formatter:function(value){ return value*100+'%'; }} ]], data:[ {price:923,quantity:2312,discount:0.2} ] }, subgrid:{ options:{ fitColumns:true, foreignField:'pid', singleSelect:true, columns:[[ {field:'pnumber',title:'Product Number',width:200}, {field:'pname',title:'Product Name',width:200}, {field:'supplier',title:'Supplier',width:200} ]], data:[ {pnumber:'00100823',pname:'Canon PowerShot A1300',supplier:'Canon'}, {pnumber:'12023423',pname:'Cisco RV110W-A-NA-K9',supplier:'Cisco'}, {pnumber:'82312393',pname:'Nikon COOLPIX L26 16.1 MP',supplier:'Nikon'} ] } } } } }; $(function(){ $('#dg').edatagrid({ title:'DataGrid - Nested SubGrid', width:700, height:300 }).datagrid('subgrid', conf); }); </script> </body> </html> Title: Re: can not set the default value of textbox and checkbox in the new added row Post by: jarry on June 15, 2016, 08:29:14 AM This is not the bug. You just call $('#dg').edatagrid('addRow'); This will append a new empty row. To append a row with initialized values, you need to call this method with a parameter value that contains the 'index' and 'row' properties.
Code: $('#dg').edatagrid('addRow',{Title: Re: can not set the default value of textbox and checkbox in the new added row Post by: Jeffrey AnnSheila on June 15, 2016, 06:13:54 PM it works now. thank you very much.
|