Created
June 7, 2011 21:05
-
-
Save stenius/1013163 to your computer and use it in GitHub Desktop.
AJAX JQuery table editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
('table#bal_out tr').delegate('td','click', (function(){ | |
cell = jQuery(this); | |
row = $(this).closest('tr'); | |
oldValue = cell.html(); | |
rowId = jQuery(row).attr('id'); | |
headerId= cell.closest('table').find('th').eq(cell.index()).attr('id'); | |
if (oldValue.indexOf('button') == -1) | |
{ | |
if ( isNaN(oldValue)) | |
{ | |
oldValue = ''; | |
} | |
cell.html('<input type="textfield" value="'+oldValue+'"></input><button class="EditCell">Change</button>') | |
$('.EditCell').button().click(function(){ | |
cell = $(this).parent(); | |
row = $(this).closest('tr'); | |
rowId = row.attr('id'); | |
headerId= cell.closest('table').find('th').eq(cell.index()).attr('id'); | |
value = $(this).parent().children('input').attr('value'); | |
payload = {'value': value,'field':headerId, 'id':rowId}; | |
$.ajaxSetup({ | |
type: 'POST', | |
data: payload, | |
success: function(data){ | |
cell.html(data); | |
} | |
}); | |
$.ajax('/biogas/api/1.0/cell/lu/bal_tank_out/'); | |
}); | |
} | |
/*alert(oldValue + ' lives on row ' + rowId + ' with the header ' + headerId);*/ | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just to clarify, each table has id in the table headers used to specify the field in the post request. The rowId is gotten from the id or the row like so