You can use callback before delete.
$crud->callback_before_delete(array($this,'cek_before_delete'));
$crud->set_lang_string('delete_error_message', 'This data cannot be deleted, because there are still a constrain data, please delete that constrain data first.');
function cek_before_delete($primary_key) {
$this->db->db_debug = false;
$this->db->trans_begin();
$this->db->where('id', $primary_key);
$this->db->delete('table_name');
$num_rows = $this->db->affected_rows();
$this->db->trans_rollback();
if ($num_rows > 0) {
return TRUE;
} else {
return FALSE;
}
}
Then you can also do the same for callback before edit with $crud->callback_before_update.