Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(document).ready(function() {
- $('.select2').select2();
- $('#project_id').select2({
- ajax: {
- url:"<?=base_url('projects/getprojectlist');?>",
- type: "post",
- dataType: 'json',
- delay:250,
- data: function (params) {
- return {
- searchTerm: params.term || "",
- page: params.page ||1
- }
- },
- processResults: function (data, params) {
- console.log(data);
- page = params.page || 1;
- return {
- results: $.map(data, function (item) { return {id: item.id, text: item.text}}),
- pagination: {
- more: (page * 10) <= data[0].total_count
- }
- };
- },
- cache:false,
- }
- });
- </script>
- public function getuserslist()
- {
- // Search term
- $searchTerm = $this->input->post('searchTerm');
- // Get Projects
- $response = $this->users_model->getUsersList($searchTerm);
- echo json_encode($response);
- }
- function getUsersList($searchTerm="")
- {
- // Fetch users
- $this->db->select('*');
- $this->db->where("first_name like '%".$searchTerm."%' ");
- $fetched_users = $this->db->get('tbl_users');
- $users = $fetched_users->result_array();
- // Initialize Array with fetched data
- $data = array();
- foreach($users as $user){
- $data[] = array("id"=>$user['id'], "text"=>$user['first_name']);
- }
- return $data;
- }
Add Comment
Please, Sign In to add comment