EasyUI Forum
May 16, 2024, 06:32:25 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: id of edatagrid in formatter  (Read 7092 times)
dnhoang
Newbie
*
Posts: 11


View Profile
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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
Logged
dnhoang
Newbie
*
Posts: 11


View Profile
« Reply #2 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?
« Last Edit: July 04, 2014, 01:07:09 AM by dnhoang » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 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
}
Logged
dnhoang
Newbie
*
Posts: 11


View Profile
« Reply #4 on: July 06, 2014, 08:32:45 PM »

Thank you stworthy, it works as perfectly as my hope! You are hero  Grin!
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!