EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: dnhoang on June 26, 2014, 11:06:34 PM



Title: id of edatagrid in formatter
Post by: dnhoang on June 26, 2014, 11:06:34 PM
In edatagrid, how to get id of current table in function of formatters such as editrow, deleterow, saverow, cancelrow.
http://www.jeasyui.com/tutorial/datagrid/datagrid12.php (http://www.jeasyui.com/tutorial/datagrid/datagrid12.php)


Title: Re: id of edatagrid in formatter
Post by: stworthy on June 26, 2014, 11:33:17 PM
Once get the row index, you can retrieve the corresponding row data.
Code:
var index = ...
var row = $('#dg').datagrid('getRows')[index];  // the row data
alert(row.id);  // the row id value


Title: Re: id of edatagrid in formatter
Post by: dnhoang on July 04, 2014, 01:01:32 AM
Thanks for your quick reply, stworthy!

But I don't want to to data of row. I want to make action formatter for general use, because I have many edatagrids in tabs, but I only want to have one formatter,  if I can get id of current table, I can call functions SAVE, CANCEL, EDIT.
For example, I have this formatter:
Code:
function actionformatter_qc01(value,row,index){
            var s = '<button onclick="save(this)">Save</button>';
            var c = '<button onclick="cancel(this)">Cancel</button>';
            var e = '<button onclick="edit(this)">Edit</button>';
if (row.editing){return s+c;} else {return e;}

function save(target){
            [b]$('#dg01')[/b].datagrid('endEdit', getRowIndex(target));
}

and I don't want to call $('#dg01') but for example $(this) or $(table_id), but it does not work.
Do you have any suggestion?


Title: Re: id of edatagrid in formatter
Post by: stworthy on July 04, 2014, 01:51:24 AM
Do you wish to get the <table> element bound to datagrid component in the 'save' function? If so, please try the code below:
Code:
function saverow(target){
  var t = $(target).closest('div.datagrid-view').children('table');
  t.datagrid('endEdit', getRowIndex(target));
  var id = t.attr('id');  // you also can get the id value of the element
}


Title: Re: id of edatagrid in formatter
Post by: dnhoang on July 06, 2014, 08:32:45 PM
Thank you stworthy, it works as perfectly as my hope! You are hero  ;D!