jquery-datatables-editable ( http://code.google.com/p/jquery-datatables-editable/ ) を使用して jQuery でテーブルを管理していますが、セルを編集するときに必要なのは、編集したばかりのセルの ID とクラスを取得します。どうやってやるの?ここに私のコードの一部があります:
//creating the table
var table = $('<table id="mytable" border="1" cellpadding="1" cellspacing="1"></table>');
var head = $('<thead><tr><th>Name</th><th>IP</th><th>Status</th><th>Last Seen</th><th>Pref. Smithers</th><th>Debug LvL</th></tr></thead>');
table.append(head);
var body = $('<tbody></tbody>');
for (var i = 0; i < x.length; i++) {
//using xml to fill the cells
var ip = x.item(i).getAttribute("id");
var row = $('<tr id="' + ip + '"></tr>');
var id = $('<td id="ip" class="' + ip + '"></td>');
var ls = $('<td id="lastseen" class="' + ip + '"></td>');
var nm = $('<td id="name" class="' + ip + '"></td>');
var st = $('<td id="status" class="' + ip + '"></td>');
var dblvl = $('<td id="defaultloglevel" class="' + ip + '"></td>');
var prfsmth = $('<td id="preferedsmithers" class="' + ip + '"></td>');
var lastseen = x.item(i).getElementsByTagName("lastseen")[0].childNodes[0].nodeValue;
var name = x.item(i).getElementsByTagName("name")[0].childNodes[0].nodeValue;
var status = x.item(i).getElementsByTagName("status")[0].childNodes[0].nodeValue;
var defaultloglevel = x.item(i).getElementsByTagName("defaultloglevel")[0].childNodes[0].nodeValue;
var preferedsmithers = x.item(i).getElementsByTagName("preferedsmithers")[0].childNodes[0].nodeValue;
nm.html(name);
id.html(ip);
st.html(status);
ls.html(lastseen);
dblvl.html(defaultloglevel);
prfsmth.html(preferedsmithers);
row.append(nm);
row.append(id);
row.append(st);
row.append(ls);
row.append(prfsmth);
row.append(dblvl);
body.append(row);
}
table.append(body);
$('#service_table').append(table);
//initiating the editable datatable
var oTable = $('#mytable').dataTable().makeEditable({
sUpdateURL: function(value, settings) {
return (value); //Simulation of server-side response using a callback function
},
"aoColumns": [
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
alert("(Cell Callback): Cell is updated with value " + sName);
}},
null
,
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
//I WANT HERE TO BE ABLE TO ALERT() THE ID AND THE CLASS OF THE CELL THAT WAS JUST EDITED
alert("(Cell Callback): Cell is updated with value " + sValue);
}},
null
,
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
alert("(Cell Callback): Cell is updated with value " + sValue);
}},
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
alert("(Cell Callback): Cell is updated with value " + sValue);
}}
]
});