[eluser]Unknown[/eluser]
Hello everybody
First of all i want to give thanks to those who read this post and wanna say this framework its really amazing

.
well the thing is that im doing a little example of DB maintenance and im doing it with jquery. its not a big deal, i just done a loggin using ajax x) and everything work good.
but what i want to do now its, from my dataTable (the grid) delete some user and refresh just the dataTable and not the entire page. what i have achieve at this moment is to call the controller from the view and delete the record i selected. but i need to refresh the grid.
to List all user from db i used the following code:
Code:
public function userList($offeset = '') {
$this->table->set_heading('User Id', 'First Name', 'Last Name', 'NickName', 'Registration Date', ' ');
$template = array('table_open' => '<table border="0" cellpadding="1" cellspacing="0" class="stripeTable"');
$this->table->set_caption('UserList (show a maximum # of ' . $this->limit . " per page)");
$this->table->set_template($template);
$config['base_url'] = site_url("userController/userList") . "/";
$config['total_rows'] = $this->UserModel->getTotalUserCount();
$config['first_link'] = 'Le First';
$config['last_link'] = 'Le Last';
$config['per_page'] = $this->limit;
$config['full_tag_open'] = '<p class="pagination">';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['userList'] = $this->UserModel->getUserList($config['per_page'], $this->uri->segment(3));
$this->load->view('viewTest/userView', $data);
}
i put an extra column with blank spaces to add the delete imagen button.
and the view its:
Code:
<html>
<head>
<scrip/t type="text/javascript" src="<?= base_url("js/jquery.js"); ?>"></scrip/t>
<scrip/t type="text/javascript" src="<?= base_url('js/jquery-ui.min.js'); ?>"></scrip/t>
<link rel="stylesheet" href="<?= base_url("css/main.css"); ?>" />
<link rel="stylesheet" href="<?= base_url('css/smoothness/jquery-ui-1.8.16.custom.css'); ?>"></link>
<scrip/t type="text/javascript" >
$(document).ready(function(){
$('.deleteLink').live('click', function(e){
e.preventDefault();
var thisLink = $(this);
var doDeleteUserMethodURL = "<?= site_url('userController/deleteUserWithId'); ?>";
var cssFolder = "<?= base_url('css'); ?>";
doDeleteUserMethodURL = doDeleteUserMethodURL +"/"+ thisLink.data('user_id');
var response = confirm("Are you sure you want to delete the selected user?");
if (response) {
$.ajax({
url: doDeleteUserMethodURL,
dataType: 'json',
success: function(data) {
$(".userDialog")
.html(data.message)
.css('background', 'url('+cssFolder+'/'+data.background+') no-repeat right')
.dialog({
autoOpen: true,
show: "explode",
hide: "hide"
})
}
});
}
});
});
</scrip/t>
<style type="text/css" >
.userDialog {
display: none;
}
</style>
</head>
<body>
<div id="divUserList">
<?php
foreach ($userList->result() as $user) {
$this->table->add_row($user->id, $user->first_name, $user->last_name, $user->nickname, $user->registration_date,
'<aa hre/f="#" data-user_id="' . $user->id . '" class="deleteLink"><img class="imageLink" src="' . base_url(" /></a>');
}
echo $this->table->generate();
echo $this->pagination->create_links();
?>
</div>
<div class="userDialog"></div>
</body>
</html>
to delete the user i use this method from controller:
Code:
public function deleteUserWithId($userId) {
$deleteUser = $this->UserModel->deleteUser($userId);
if ($deleteUser) { # user was deleted
$message = 'user Deleted successfully';
$status = 'ok';
$background = 'images/trashCan.png';
} else { # something went wrong
$message = 'user couldnt be deleted, something went wrong';
$status = 'error';
$background = 'images/error.png';
}
$returnedData = array(
'message' => $message,
'status' => $status,
'background' => $background
);
$json_encode = json_encode($returnedData);
echo $json_encode;
}
with all these code, the user selected is deleted from databse, but i dont know how to refresh the just the table.
i tried to do this with jquery but ir didnt work:
Code:
thisLink.parent('tr').hide('slow');
i hope some of you could help me. anyway i will continue searching and if i find a way to achieve this i'll post it.