Realtime Editing without Web Socket | Socket.io | Real Time Editor | Auto Refresh inline real time
Realtime Editing without Web Socket | Socket.io | Real Time Editor | Auto Refresh inline real time
aungkohein
Posts: 38Questions: 5Answers: 0
Hi guy!
With the help of Allan, I managed to find a workaround for real time effect on Datatables Editor.
It is not easy to integrate web socket with inline editing. Here is the concept for workaround:
- Use ajax.reload() - to refresh the table (without refreshing the page)
- Use setInterval() - to set frequency for auto refresh
- Use clearInterval() - to stop auto refresh only when editing in the cell
That will give you a real time experience to your clients!
Steps:
File: js/table.youTableName.js
1.
//Auto Refresh (ajax.reload)
var refreshTable = setInterval( function () {
table.ajax.reload( null, false ); // user paging is not reset on reload
table.keys.enable();
}, 3000 ); //3000 means 3 seconds; you cannot put 0 -> error
2.
// Activate an inline edit on click of a table cell
$('#youTableName').on( 'keyup', 'tbody td:not(:first-child)', function (e) {
clearInterval( refreshTable );
table.keys.disable();
});
// Inline editing on tab focus
$('#youTableName').on( 'keydown', 'tbody td:not(:first-child)', function (e) {
clearInterval( refreshTable );
table.keys.disable();
});
// Activate an inline edit on click of a table cell
$('#youTableName').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
submitOnBlur: true
});
clearInterval( refreshTable );
table.keys.enable();
});
//Additional codes if you want to submit using TAB in inline editing
// when tab key is pressed
$('#youTableName').on( 'keydown', 'tbody', function (e) {
if(e.which == 9) {
e.preventDefault();
var $input = $('form input');
$input.eq( $input.index( this ) + 1 ).focus();
table.keys.enable();
}
} );
This discussion has been closed.
Replies
Thanks for posting this .
Allan
Missed out this:
Add this to the above codes:
// To restart auto refresh after cell edited
editor.on( 'close', function () {
setInterval( function () {
table.ajax.reload( null, false ); // user paging is not reset on reload
table.keys.enable();
}, 3000 );
} );
[UPDATED]
Hi guys!
The above codes works pretty fine but after few round of testings, it has a loophole which does not make editing smooth. Hence, please use the code below instead!
Steps:
File: js/table.youTableName.js
} );
// when tab key is pressed
editor.on( 'close', function () {
table.keys.enable();
refreshTable();
} );
// Inline editing on tab focus
//table.on( 'key-focus', function ( e, datatable, cell ) {
// editor.inline( cell.index() );
//} );
refreshTable();
-------------- end --------------------