server side filtering delay
server side filtering delay
predrag.music
Posts: 8Questions: 0Answers: 0
Hi Allan,
I'm building my first application with datatables and thay are easy to work. I realy like them and best of all they are very stabile so far:)
But, i have a problem with server side filtering delay. I read http://datatables.net/plug-ins/api#fnSetFilteringDelay and a few forum posts but that didn't solve my problem.
Since i'm using jeditable, TableTools, KeyTable and a some other stuff and things are getting too complicated (for me).
I supose that the problem with filtering delay is in some relation with KeyTable plugin but i don't have enough knoledge with javascript and datatables to solve this myself.
With the code bellow filtering delay doesn't work at all.
I added unbind('keypress') in fnSetFilteringDelay plugin but that didn't help.
I appreciate your help with this problem.
[code]
jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function (oSettings, iDelay) {
var _that = this;
this.each( function ( i ) {
$.fn.dataTableExt.iApiIndex = i;
var iDelay = (iDelay && (/^[0-9]+$/.test(iDelay)) ? iDelay : 250),
$this = this,
oTimerId = null,
sPreviousSearch = null,
anControl = $( 'div.dataTables_filter input:text', _that.fnSettings().aanFeatures.f );
//added unbind('keypress')
anControl.unbind( 'keyup' ).unbind('keypress').bind( 'keyup', function() {
var $$this = $this;
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function() {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter( anControl.val() );
}, iDelay);
}
});
return this;
} );
return this;
}
$(document).ready(function() {
TableToolsInit.sSwfPath = "<?php echo base_url();?>swf/ZeroClipboard.swf";
var nCloneTd = document.createElement( 'td' );
nCloneTd.innerHTML = '';
nCloneTd.className = "center";
$('#data tbody tr').each( function () {
this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] );
} );
oTable = $('#data').dataTable({
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bLengthChange": true,
"bInfo": true,
"bFilter": true,
"bStateSave": true,
"bSortClasses": false,
"sAjaxSource": '<?php echo site_url();?>/message/json_data',
"sDom": 'T<"H"flr>t<"F"ilp>',
"aaSorting": [[1,'desc'], [2,'desc'] ],
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$(nRow).attr("id",aData[1]);
if(!aData[4].length){
$(nRow).attr("class","prazno");
}else{
}
return nRow;
},
"oLanguage": {
"sUrl": "<?php echo base_url(); ?>js/dev/jquery.dataTables.hr.txt"
},
"bAutoWidth" : false,
"aoColumns": [
null,
null,
null,
null,
null,
null
],
"fnDrawCallback": function (oSettings) {
var keys = new KeyTable( {
"table": document.getElementById('data')
} );
keys.event.action( null, null, function (nCell) {
keys.block = true;
$('#data tbody td').editable( '<?php echo site_url();?>/message/updateWorkLog', {
indicator : '',
"onblur": 'submit',
type: 'clear_input',
tooltip: 'Klikni...',
submitdata : function() {
return {
id : $(this).parent().attr("id"),
col: $(this).parent().children().index($(this))
};
},
"onreset": function(){
setTimeout( function () {keys.block = false;}, 0);
},
"callback": function( sValue, y ) {
oTable.fnDraw();
},
"height": "14px"
});
setTimeout( function () { $(nCell).click(); }, 0 );
});
if ( oSettings.aiDisplay.length == 0 ){
return;
}
}
}).fnSetFilteringDelay();
});
[/code]
Thank You,
Predrag Music
I'm building my first application with datatables and thay are easy to work. I realy like them and best of all they are very stabile so far:)
But, i have a problem with server side filtering delay. I read http://datatables.net/plug-ins/api#fnSetFilteringDelay and a few forum posts but that didn't solve my problem.
Since i'm using jeditable, TableTools, KeyTable and a some other stuff and things are getting too complicated (for me).
I supose that the problem with filtering delay is in some relation with KeyTable plugin but i don't have enough knoledge with javascript and datatables to solve this myself.
With the code bellow filtering delay doesn't work at all.
I added unbind('keypress') in fnSetFilteringDelay plugin but that didn't help.
I appreciate your help with this problem.
[code]
jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function (oSettings, iDelay) {
var _that = this;
this.each( function ( i ) {
$.fn.dataTableExt.iApiIndex = i;
var iDelay = (iDelay && (/^[0-9]+$/.test(iDelay)) ? iDelay : 250),
$this = this,
oTimerId = null,
sPreviousSearch = null,
anControl = $( 'div.dataTables_filter input:text', _that.fnSettings().aanFeatures.f );
//added unbind('keypress')
anControl.unbind( 'keyup' ).unbind('keypress').bind( 'keyup', function() {
var $$this = $this;
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function() {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter( anControl.val() );
}, iDelay);
}
});
return this;
} );
return this;
}
$(document).ready(function() {
TableToolsInit.sSwfPath = "<?php echo base_url();?>swf/ZeroClipboard.swf";
var nCloneTd = document.createElement( 'td' );
nCloneTd.innerHTML = '';
nCloneTd.className = "center";
$('#data tbody tr').each( function () {
this.insertBefore( nCloneTd.cloneNode( true ), this.childNodes[0] );
} );
oTable = $('#data').dataTable({
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bLengthChange": true,
"bInfo": true,
"bFilter": true,
"bStateSave": true,
"bSortClasses": false,
"sAjaxSource": '<?php echo site_url();?>/message/json_data',
"sDom": 'T<"H"flr>t<"F"ilp>',
"aaSorting": [[1,'desc'], [2,'desc'] ],
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$(nRow).attr("id",aData[1]);
if(!aData[4].length){
$(nRow).attr("class","prazno");
}else{
}
return nRow;
},
"oLanguage": {
"sUrl": "<?php echo base_url(); ?>js/dev/jquery.dataTables.hr.txt"
},
"bAutoWidth" : false,
"aoColumns": [
null,
null,
null,
null,
null,
null
],
"fnDrawCallback": function (oSettings) {
var keys = new KeyTable( {
"table": document.getElementById('data')
} );
keys.event.action( null, null, function (nCell) {
keys.block = true;
$('#data tbody td').editable( '<?php echo site_url();?>/message/updateWorkLog', {
indicator : '',
"onblur": 'submit',
type: 'clear_input',
tooltip: 'Klikni...',
submitdata : function() {
return {
id : $(this).parent().attr("id"),
col: $(this).parent().children().index($(this))
};
},
"onreset": function(){
setTimeout( function () {keys.block = false;}, 0);
},
"callback": function( sValue, y ) {
oTable.fnDraw();
},
"height": "14px"
});
setTimeout( function () { $(nCell).click(); }, 0 );
});
if ( oSettings.aiDisplay.length == 0 ){
return;
}
}
}).fnSetFilteringDelay();
});
[/code]
Thank You,
Predrag Music
This discussion has been closed.
Replies
If maybe someone has an idea...?
Thank You
Predrag Music
But you can add a live handler to the button.
[code]
anControl.unbind( 'keyup' ).live( 'keyup', function() { ...});
[/code]
console.info(anControl) shows "jQuery ( )" instead of "jQuery ( input )"
I don't know why, maybe the input search is built after the plugin was loaded.
When the plugin is loading fnSettings().aanFeatures returns an empty array.
Allan please, help us, you are the only hope.
It appears that the drawing method of filter, _fnFeatureHtmlFilter is loaded after the plugin in my case.
It appears that the load of extra language in jSon is the issue.
Line 5036, the language file is load and the dataTable tries to initialize in _fnLanguageProcess.
Unfortunately I have the very same problem. :-( I already updated to 1.7.5, but the error remains. If I uncomment my "oLanguage" settings, everythings works like expected. Any chance to fix that bug?
Thanks a lot in advance!
Allan
thanks a bunch, that helped a great deal. Works perfect.
I'll see to get some donations to you for your help and DataTable itself.
CU