Custom search Datatables

Custom search Datatables

macmacmacmac Posts: 4Questions: 0Answers: 0
edited May 2013 in General
hi all,

I'm new to datatables and I'm encountering some problems, basically I'm building a custom search for my table. here is the html code.
[code]


Search By

ID
Name
Code







[/code]

I'm using fnFilter for this, I understand the use of sSearch_(index of field). Here is my javascript code.
[code]
$('#btn_search').on('click', function(e) {
if(!$('#search_value').val()) {
e.preventDefault();
$('#search_value').addClass('border_red');
} else {
e.preventDefault();
$('#sa_merchant_table').dataTable().fnFilter($('#search_value').val(), $('#search_field').val());
}
});
[/code]

Basically what I want to do is to get the field which I want to filter and search the value which is comming from the textbox. The initial search is working fine, Let say I selected [code]Name[/code] then put some value in the textbox. It works great, my problem is when I want to search again for another field [code]Code[/code]. It seems like the first sSearch_(index of field) is not cleared or lost it's value. I'm still getting the result of for my first search. BTW I'm using server side processing. If it's going to help you here is my php code

[code]

if(isset($_GET['sSearch_0']) && $_GET['sSearch_0'] != '') {
$merchant_api = $this->super_model->search_merchant(trim($_GET['sSearch_0']), NULL, NULL, $_GET['iDisplayLength'], $_GET['iDisplayStart'], $field, $order);
$filter_count = $merchant_api->count;
unset($_GET['sSearch_0']);
$_GET['sSearch_0'] = '';
} else if(isset($_GET['sSearch_1']) && $_GET['sSearch_1'] != '') {
$merchant_api = $this->super_model->search_merchant(NULL, trim($_GET['sSearch_1']), NULL, $_GET['iDisplayLength'], $_GET['iDisplayStart'], $field, $order);
$filter_count = $merchant_api->count;
unset($_GET['sSearch_1']);
$_GET['sSearch_1'] = '';
} else if(isset($_GET['sSearch_2']) && $_GET['sSearch_2'] != ''){
$merchant_api = $this->super_model->search_merchant(NULL, NULL, trim($_GET['sSearch_2']), $_GET['iDisplayLength'], $_GET['iDisplayStart'], $field, $order);
$filter_count = $merchant_api->count;
unset($_GET['sSearch_2']);
$_GET['sSearch_2'] = '';
[/code]

Thanks in advance guys.
-Mac
This discussion has been closed.