Title: get data from detail grid Post by: naqib on June 08, 2012, 02:17:12 AM Hello everyone:
I want to get the selected row data and insert it into my form which I have done, however, I want to get the detail data as well with the same click to store it in my next form my code is: $('#dg').datagrid({ view: detailview, detailFormatter:function(index,row){ return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>'; }, onExpandRow: function(index,row){ $('#ddv-'+index).datagrid({ url:'<?php echo ROOT_WEB ?>model/searchProductDetail.php?product_code='+row.product_code, fitColumns:true, singleSelect:true, height:'auto', columns:[[ {field:'draw_name',title:'Drawing',width:60}, {field:'description',title:'Description',width:200}, {field:'draw_link',title:'File',width:60} ]], onResize:function(){ $('#dg').datagrid('fixDetailRowHeight',index); }, onLoadSuccess:function(){ setTimeout(function(){ $('#dg').datagrid('fixDetailRowHeight',index); },0); } }); $('#dg').datagrid('fixDetailRowHeight',index); }, onClickRow: function(rowData, rowIndex) { var row = $('#dg').datagrid('getSelected'); if (row){ $('#productcode').val(row.product_code); $('#productname').val(row.product_name); $('#clientpartno').val(row.client_partno); $('#revision').val(row.revision); $('#description').val(row.description); $('.combo input').val(row.client_id); } } Title: Re: get data from detail grid Post by: stworthy on June 11, 2012, 12:55:47 AM Get the detail datagrid object and then you can get the detail data.
Code: $('#dg').datagrid({ onClickRow: function(rowIndex,rowData){ var ddv = $('#ddv-'+rowIndex); // the detail datagrid object var rows = ddv.datagrid('getRows'); // get the detail datagrid rows } }); Title: Re: get data from detail grid Post by: naqib on June 13, 2012, 12:30:20 AM thanks for reply,
I did add this code it does not work, for test purpose I checked it is not printing the rows data in alert onClickRow: function(rowData,rowIndex) { var ddv = $('#ddv-'+rowIndex); // the detail datagrid object var rows = ddv.datagrid('getRows'); // get the detail datagrid rows alert(rows + " " + rowData); } any idea? Title: Re: get data from detail grid Post by: stworthy on June 13, 2012, 01:32:53 AM Be sure to expand a row before getting that row data. Try below code again:
Code: $('#dg').datagrid({ onClickRow: function(rowIndex){ var detailContainer = $(this).datagrid('getRowDetail', rowIndex); if (detailContainer.find('div.datagrid').length){ // the detail datagrid has been created var ddv = $('#ddv-'+rowIndex); // the detail datagrid object var rows = ddv.datagrid('getRows'); // get the detail datagrid rows console.log(rows) } } }); Title: Re: get data from detail grid Post by: naqib on June 14, 2012, 01:24:12 AM When I saw the code you provided to me I thought It will work, but once again no hope, please see my code may be I have did some other mistake:
$('#dg').datagrid({ view: detailview, detailFormatter:function(index,row){ return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>'; }, onExpandRow: function(index,row){ $('#ddv-'+index).datagrid({ url:'<?php echo ROOT_WEB ?>model/searchStandard.php?product_code='+row.product_code, fitColumns:true, singleSelect:true, height:'auto', columns:[[ {field:'product_code',title:'Product Code',width:60}, {field:'commitee',title:'Commitee',width:200}, {field:'stand_title',title:'Standard',width:60}, {field:'stand_link',title:'Standard File',width:60}, {field:'description',title:'Description',width:60} ]], onResize:function(){ $('#dg').datagrid('fixDetailRowHeight',index); }, onLoadSuccess:function(){ setTimeout(function(){ $('#dg').datagrid('fixDetailRowHeight',index); },0); }, onClickRow: function(rowIndex){ var detailContainer = $(this).datagrid('getRowDetail', rowIndex); if (detailContainer.find('div.datagrid').length){ // the detail datagrid has been created var ddv = $('#ddv-'+rowIndex); // the detail datagrid object var rows = ddv.datagrid('getRows'); // get the detail datagrid rows alert(rows); } } }); $('#dg').datagrid('fixDetailRowHeight',index); } }); Title: Re: get data from detail grid Post by: stworthy on June 14, 2012, 05:34:11 AM You put the 'onClickRow' handler code in wrong place. The updated code is showed as below:
Code: $('#dg').datagrid({ view: detailview, detailFormatter:function(index,row){ return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>'; }, onExpandRow: function(index,row){ $('#ddv-'+index).datagrid({ url:'<?php echo ROOT_WEB ?>model/searchStandard.php?product_code='+row.product_code, fitColumns:true, singleSelect:true, height:'auto', columns:[[ {field:'product_code',title:'Product Code',width:60}, {field:'commitee',title:'Commitee',width:200}, {field:'stand_title',title:'Standard',width:60}, {field:'stand_link',title:'Standard File',width:60}, {field:'description',title:'Description',width:60} ]], onResize:function(){ $('#dg').datagrid('fixDetailRowHeight',index); }, onLoadSuccess:function(){ setTimeout(function(){ $('#dg').datagrid('fixDetailRowHeight',index); },0); } }); $('#dg').datagrid('fixDetailRowHeight',index); }, onClickRow: function(rowIndex){ var detailContainer = $(this).datagrid('getRowDetail', rowIndex); if (detailContainer.find('div.datagrid').length){ // the detail datagrid has been created var ddv = $('#ddv-'+rowIndex); // the detail datagrid object var rows = ddv.datagrid('getRows'); // get the detail datagrid rows alert(rows); } } }); Title: Re: get data from detail grid Post by: naqib on June 14, 2012, 06:24:37 AM Thanks for replay:
I replaced the code, now I get no alert message when I press on parent record, however, when I collapse the row and select one of detail row and come back and click on parent row it gives me: [object Object],[object Object],[object Object] in alert box! :( please help me I very new Title: Re: get data from detail grid Post by: naqib on June 18, 2012, 04:40:16 AM I did solve it like this:
$(function(){ $('#dg').datagrid({ view: detailview, detailFormatter:function(index,row){ return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>'; }, onExpandRow: function(index,row) { $('#ddv-'+index).datagrid( { url:'<?php echo ROOT_WEB ?>model/searchStandard.php?product_code='+row.product_code, fitColumns:true, singleSelect:true, height:'auto', columns:[[ {field:'product_code',title:'Product Code',width:60}, {field:'commitee',title:'Commitee',width:200}, {field:'stand_title',title:'Standard',width:60}, {field:'stand_link',title:'Standard File',width:60}, {field:'description',title:'Description',width:60}, {field:'stand_no',title:'Standard No',width:60} ]], onResize:function() { $('#dg').datagrid('fixDetailRowHeight',index); }, onLoadSuccess:function() { setTimeout(function(){ $('#dg').datagrid('fixDetailRowHeight',index); },0); }, onSelect: function() { getSelected(index); } }); $('#dg').datagrid('fixDetailRowHeight',index); } }); }); function getSelected(index){ var row = $('#dg').datagrid('getRows'); var drow = $('#ddv-'+index).datagrid('getSelected'); setValue(drow); } function getDelete() { $.messager.alert('Info', 'Deletion failed!', 'info'); } function setValue(drow) { $('#cstand_pcode').val(drow.product_code); $('#cstand_commitee').append('<option selected>' + drow.commitee + '</option>'); $('#cstand_name').val(drow.stand_no); window.top.document.getElementById("footer").src = "<?php echo ROOT_WEB ?>public/files/standUpload/"+drow.stand_link; } Thanks for your help |