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.
I'm using fnFilter for this, I understand the use of sSearch_(index of field). Here is my javascript 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
Thanks in advance guys.
-Mac
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.
<form class="form-inline pull-left" method="GET" action="/super/merchant/"> <label> Search By <select name="search_field" id="search_field" class="input-small"> <option value="0">ID</option> <option value="1">Name</option> <option value="2">Code</option> </select> </label> <div class="input-append"> <input type="text" name="search_value" id="search_value" placeholder="Enter Value" value=""> <button class="btn" type="submit" name="search" id="btn_search" value="Search"><span class="icon icon-search"></span></button> </div> </form>
I'm using fnFilter for this, I understand the use of sSearch_(index of field). Here is my javascript 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()); } });
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
<option value="1">Name</option>then put some value in the textbox. It works great, my problem is when I want to search again for another field
<option value="2">Code</option>. 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
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'] = '';
Thanks in advance guys.
-Mac