Im using Jquery widget Autocomplete.My data source is a server-side script which returns JSON data.
$(function() {
$( "#supcode" ).autocomplete({
source:"index.php/inventory/supcode",
minLength: 1
});
});
Im using MVC architecture (Codeigniter) and using following method in controller to return the JSON data,
function supcode()
{
$dataarray="";
$data=$this->Inventorymodel->supcode();
echo json_encode($data);
}
And I am fetching the data in model using following function,
function supcode(){
$finresult="";
$this->db->select('name');
$query = $this->db->get('supplier');
$result=$query->result_array();
foreach($result as $row){
$finresult[]=array(
'name' => $row['name']
);
}
return $finresult;
}
When I type a letter in the textbox filtering is not working and all the items are listed.What have I done wrong here? Can anyone help me? Thanks in advance….
You need to complete the filtering on the server side (as stated in the comments to the question by @Henrik) and the Expected data format needs to be an array of objects with
labelandvalueas the fields.See this link jQuery Autocomplete.