[SOLVED] Search with "enter key" problem

[SOLVED] Search with "enter key" problem

ianraphaianrapha Posts: 2Questions: 0Answers: 0
edited July 2011 in General
I'm using datatables on my application and i made a customization to search just when user presses enter.

The code that generates the table is below.

[code]

var oCache = { iCacheLower: -1 };
var configTable = {
"bProcessing": true
, "bServerSide": true
, "bJQueryUI": true
, "bAutoWidth": false
, "sAjaxSource": "/paginacao/!data.cfm?filter=#variables.filter#&columns=#variables.columns#&cfc=#variables.cfc#&method=#variables.method#&tableId=#arguments.tableId#"
, "fnServerData": fnDataTablesPipeline
, "bSort": true
};

$(document).ready(function(){
oTable = $('#tbbatch').dataTable(configTable);

$('.dataTables_filter input').unbind('keypress keyup').bind('keypress keyup', function(e){
if (e.which == 13){
oTable.fnFilter($(this).val(), null, false, true);
}
});

$('#tbbatch_searchIcon').live('click',function(e){
oTable.fnFilter($('.dataTables_filter input').val(), null, false, true);
});

});

[/code]

The code below i inserted in jquery.datatables.js to put a search image in right side of input text.

[code]
nFilter.innerHTML = oSettings.oLanguage.sSearch+sSpace+'';
[/code]

The problem is that i need to press enter twice to show the new content of search. On the first enter the ajax request is triggered but the table data are not updated. When i press again the data is updated with the json return of the call.

The image click (tbbatch_searchIcon) search works perfect.

I'm using the datatables pipeline for pagination and ColdFusion's SerializeJSON function for generate the json return.

Replies

  • ianraphaianrapha Posts: 2Questions: 0Answers: 0
    Problem solved.

    The issue was on bind('keypress keyup'). It was generating two events with different keycodes. I removed the keypress and the script works like a charm!
This discussion has been closed.