0

I'm using datatable and want to refresh table using ajax.reload(). For that, i need to send all table with json statement. my code is this:

function relaod_table(){
        $data = $this->admin_model->get_user();     
        for ($i=0; $i < count($data) ; $i++) {
            $more = '<button type="button" id="'.$data[$i]['user_id'].'">test</button>';
            $data[$i]['more'] = $more;
        }
        echo json_encode(array('data' => $data));
}

The received data is correct and each button has the id which is the user_id. The problem is when i call the id, It doesn't triggers and nothing happen.

$( "#234" ).click(function() {
  alert( "Handler for .click() called." );
});

My questions are

1: how can i trigger the button's by id?

2: If i wanna use onclick() function for the buttons, when i send the json, i get the error that says Call to undefined function delete_user(). Can i use onclick in this situation?

$more =  '<button type="button" id="'.$data[$i]['user_id'].'" onclick="'.delete_user().'">test</button>';

3: How can i trigger the button i click on?

Thanks in advance.

1 Answers1

0

Try using this

$('table').on('click', '#234', function() { 
        code here 
});

But call this with class and use data-* parameter to get user_id. Hope this helps you

Romius
  • 16
  • 2