Код: Выделить всё
Time from
Time to
Enabled
16:01
23:01
true
[i][/i]
10:00
11:00
false
[i][/i]
[i][/i]
Код: Выделить всё
//function for when the addrow action is used
$('#addRow').on('click',function(){
$('#schedules > tbody:last-child').append('[i][/i]');
//function for when the save new row icon is pressed
$('#saveicon').on('click',function(){
//Send data to script to store as now row in db
$.get( "/settings/insertSchedule/" + $('#newrow input#time_from').val() + "/" + $('#newrow input#time_to').val() + "/" + $('#newrow input#enabled').val() , function( data ) {
//Change input fields to text fields
$('#newrow td#time_from').text($('#newrow input#time_from').val());
$('#newrow td#time_to').text($('#newrow input#time_to').val());
$('#newrow td#enabled').text($('#newrow input#enabled').val());
//change checkmark icon into edit icon
$('#newrow i#saveicon').attr('class', 'fa fa-pencil-square-o fa-fw');
$('#newrow i#saveicon').attr('id', 'editicon');
$('#newrow td#saveicon').attr('id', 'edit');
$('#newrow').attr('id',data);
console.log(data);
});
});
});
//function for when the edit row icon is clicked
var arr = {};
$('#schedules').on('click','#edit',function() {
var rowid = ($(this).parent().attr('id'));
$(this).siblings().each(
function(){
//end of editing, change the icon back to a pencil and change the fields back to text
if ($(this).find('input').length){
$(this).text($(this).find('input').val());
$('#editicon').attr('class', 'fa fa-pencil-square-o fa-fw');
arr[this.id] = $(this).html()
}
else {
//start of editing, change fields to input fields and icon to checkmark
var t = $(this).text();
$(this).html($('',{'value' : t}).val(t));
$('#editicon').attr('class', 'fa fa-check fa-fw');
}
});
//Send updated data to script to store in DB.
if (Object.keys(arr).length > 0){
$.get( "/settings/updateSchedule/" + rowid + "/" + arr.time_from + "/" + arr.time_to , function( data ) {});
}
});
Подробнее здесь: https://stackoverflow.com/questions/351 ... e-datagrid
Мобильная версия