multiple delete selection
Posted 09 May 2012 - 15:25 PM
But I want to have some functionality which might not be in default don't know how to achieve that.. so i need help here..
1. i have created custom action to update certain column on a click (i.e column with field type enum)... after updating column through custom action.. i want to refresh table diaplaying changes with message of update.. how can i do that rather than presently what i am doing, redirecting page displaying table....
2. there is no multiple data selection delete option in grocery crud.. how can that be done... please help me out...(more importantly i want this problem to get solved... needed fast.. help me out guyzz)
Posted 09 May 2012 - 18:14 PM
1. There is a hidden div with id report-success so you can full it with a paragraph and your message and it will work fine. You can have for example:
$('#report-success').html("<p>Your data has been successfully updated</p>").slideDown();
2. For this I don't have any example, help or tip to give you as I didn't try it yet.
Posted 09 May 2012 - 19:52 PM
Anyway here we go:
[attachment=169:example.PNG]
Above is an example, added the check links to the side and a delete all selected button to the bottom right. Here is the "list.php" file, download it and copy to your flexigrid theme (backup your current one) path: assets\grocery_crud\themes\flexigrid\views.
[attachment=170:list.php]
You will need to edit the javascript part around line 25 and replace your own URL in here.
Here's an example function for the controller:
function delete_selection()
{
$id_array = array();
$selection = $this->input->post("selection", TRUE);
$id_array = explode("|", $selection);
foreach($id_array as $item):
if($item != ''):
//DELETE ROW
$this->db->where('customerNumber', $item);
$this->db->delete('customers');
endif;
endforeach;
}
Posted 09 May 2012 - 21:23 PM
So please just be patient.
[member='casachit '] tell to your client that we are doing our best to have a stable CRUD so convenience him just for now that it is not so important functionality. If you REALLY want this to be done just follow the instructions of KaBaDaBrA that will work for sure and just be careful at the next update.
Thanks KaBaDaBrA for the help.
Posted 13 May 2012 - 03:09 AM
Posted 09 November 2012 - 16:56 PM
THX. Work great.
Posted 20 December 2012 - 08:14 AM
Copy this at the begin of list.php (flexigrid)
<script type="text/javascript">
$(document).ready(function(){
$('input[type=checkbox]').click( function(){
if($(this).is(':checked')){
$('#delete-selected-item').removeAttr('disabled');
}else{
if(!$('input[name=custom_delete]').is(':checked')){
$('#delete-selected-item').attr('disabled','disabled');
$('.checkall').removeAttr('checked');
}
}
});
});
$(function () {
//CHECK ALL BOXES
$('.checkall').click(function () {
if($(this).is(':checked')){
$('#delete-selected-item').removeAttr('disabled');
}else{
$('#delete-selected-item').attr('disabled','disabled');
}
$(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
});
//ADD DELETE BUTTON
if($('.pDiv2 .delete_all_button').length == 0) { //check if element already exists (for ajax refresh purposes)
$('.pDiv2').append('<input id="delete-selected-item" type="button" value="Delete Selected" class="delete_all_button" onclick="delete_selected()" style="top: 0px";>');
$('#delete-selected-item').attr('disabled','disabled');
}
});
function delete_selected()
{
var list = "";
$('input[type=checkbox]').each(function() {
if (this.checked) {
//remove selection rows
$('#custom_tr_'+this.value).remove();
//create list of values that will be parsed to controller
list += this.value + '|';
}
});
//send data to delete
$.post('<?=base_url();?>admin/delete_selection', { selection: list }, function(data) {
alert('Deleted !');
});
}
</script>
Ps.web-johnny can add list.php with modified content.
Posted 11 January 2013 - 07:21 AM
For your [b]number 2[/b] I tested something quickly and works quite well, however it is static - not sure how to find the dynamically parsed values in the list like the table name being used, nor the field for the primary id. If I could find them it's really easy to change over to be dynamic. Maybe Johnny could give a hand here
Anyway here we go:
[attachment=169:example.PNG]
Above is an example, added the check links to the side and a delete all selected button to the bottom right. Here is the "list.php" file, download it and copy to your flexigrid theme (backup your current one) path: assets\grocery_crud\themes\flexigrid\views.
[attachment=170:list.php]
You will need to edit the javascript part around line 25 and replace your own URL in here.
Here's an example function for the controller:
function delete_selection()
{
$id_array = array();
$selection = $this->input->post("selection", TRUE);
$id_array = explode("|", $selection);
foreach($id_array as $item):
if($item != ''):
//DELETE ROW
$this->db->where('customerNumber', $item);
$this->db->delete('customers');
endif;
endforeach;
}
[/quote]
why my data cannot be delete after i use function?
[quote]
[color=#000088]function[/color][color=#000000] delete_selection[/color][color=#666600]()[/color]
[color=#666600]{[/color]
[color=#000000] $id_array [/color][color=#666600]=[/color][color=#000000] array[/color][color=#666600]();[/color]
[color=#000000] $selection [/color][color=#666600]=[/color][color=#000000] $this[/color][color=#666600]->[/color][color=#000000]input[/color][color=#666600]->[/color][color=#000000]post[/color][color=#666600]([/color][color=#008800]"selection"[/color][color=#666600],[/color][color=#000000] TRUE[/color][color=#666600]);[/color]
[color=#000000] $id_array [/color][color=#666600]=[/color][color=#000000] explode[/color][color=#666600]([/color][color=#008800]"|"[/color][color=#666600],[/color][color=#000000] $selection[/color][color=#666600]);[/color]
[color=#000000] [/color][color=#000088]foreach[/color][color=#666600]([/color][color=#000000]$id_array [/color][color=#000088]as[/color][color=#000000] $item[/color][color=#666600]):[/color]
[color=#000000] [/color][color=#000088]if[/color][color=#666600]([/color][color=#000000]$item [/color][color=#666600]!=[/color][color=#000000] [/color][color=#008800]''[/color][color=#666600]):[/color]
[color=#000000] [/color][color=#880000]//DELETE ROW[/color]
[color=#000000] $this[/color][color=#666600]->[/color][color=#000000]db[/color][color=#666600]->[/color][color=#000088]where[/color][color=#666600]([/color][color=#008800]'trxnum'[/color][color=#666600],[/color][color=#000000] $item[/color][color=#666600]);[/color]
[color=#000000] $this[/color][color=#666600]->[/color][color=#000000]db[/color][color=#666600]->[/color][color=#000088]delete[/color][color=#666600]([/color][color=#008800]'paylog'[/color][color=#666600]);[/color]
[color=#000000] endif[/color][color=#666600];[/color]
[color=#000000] endforeach[/color][color=#666600];[/color]
[color=#666600]}[/color]
[/quote]
here`s my code controller after i add that function
[quote]
function logger_management()
{
try{
$crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('paylog');
$crud->set_subject('Paylog');
$crud->columns('trxnum','trxdat','reqmsg','resmsg','msgtyp','procod','rspcod','busdat','noreff');
$crud->required_fields('trxnum','trxdat','reqmsg','resmsg','msgtyp','procod','rspcod','busdat','noreff');
$crud->unset_edit();
$this->_delete_selection();
$output = $crud->render();
$this->_logger_output($output);
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
[/quote]
Posted 11 January 2013 - 08:23 AM
1)You have a function called "delete_selection", but you use another name "_delete_selection";
2) Why do you use that function inside other method?
3) did you changed the url in list.php?
Posted 11 January 2013 - 08:32 AM
Hi phenom1711 and welcome to the forum!
1)You have a function called "delete_selection", but you use another name "_delete_selection";
2) Why do you use that function inside other method?
3) did you changed the url in list.php?
[/quote]
1. sorry..i was change to
[quote]
public function _delete_selection()
{
$id_array = array();
$selection = $this->input->post("selection", TRUE);
$id_array = explode("|", $selection);
foreach($id_array as $item):
if($item != ''):
//DELETE ROW
$this->db->where('cardno', $item);
$this->db->delete('paycust',$item);
endif;
endforeach;
}
[/quote]
2. so, how i must put that function?
3. yes..i was change it..
[quote]
function delete_selected()
{
var list = "";
$('input[type=checkbox]').each(function() {
if (this.checked) {
//remove selection rows
$('#custom_tr_'+this.value).remove();
//create list of values that will be parsed to controller
list += this.value + '|';
}
});
//send data to delete
$.post('<?=base_url();?>/index.php/mainlog/logger', { selection: list }, function(data) {
alert('Deleted !');
});
}
</script>
sorry for my english
[/quote]
Posted 11 January 2013 - 08:39 AM
function logger_management()
{
}
// note: name is "delete_selection"
public function delete_selection()
{
}
javascript:
function delete_selected()
{
// ........
// change the url
$.post('<?=base_url();?>/index.php/mainlog/delete_selection', { selection: list }, function(data) {
alert('Deleted !');
});
}
Posted 11 January 2013 - 08:54 AM
function logger_management()
{
}
// note: name is "delete_selection"
public function delete_selection()
{
}
javascript:
function delete_selected()
{
// ........
// change the url
$.post('<?=base_url();?>/index.php/mainlog/delete_selection', { selection: list }, function(data) {
alert('Deleted !');
});
}
[/quote]
my url is
[quote]
[color=#000088]function[/color][color=#000000] delete_selected[/color][color=#666600]()[/color]
[color=#666600]{[/color]
[color=#880000]// ........[/color]
[color=#880000]// change the url[/color]
[color=#000000] $[/color][color=#666600].[/color][color=#000000]post[/color][color=#666600]([/color][color=#008800]'<?=base_url();?>/index.php/mainlog/logger'[/color][color=#666600],[/color][color=#000000] [/color][color=#666600]{[/color][color=#000000] selection[/color][color=#666600]:[/color][color=#000000] list [/color][color=#666600]},[/color][color=#000000] [/color][color=#000088]function[/color][color=#666600]([/color][color=#000000]data[/color][color=#666600])[/color][color=#000000] [/color][color=#666600]{[/color]
[color=#000000] alert[/color][color=#666600]([/color][color=#008800]'Deleted !'[/color][color=#666600]);[/color]
[color=#000000] [/color][color=#666600]});[/color]
[color=#666600]}[/color]
[/quote]
not delete_selection. i was put this function into logger controller
[quote]
class Logger extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('grocery_CRUD');
$this->load->library('tank_auth');
}
function _logger_output($output = null)
{
$this->load->view('logger.php',$output);
}
function logger()
{
$output = $this->grocery_crud->render();
$this->_logger_output($output);
}
function index()
{
$this->_logger_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
}
public function delete_selection()
{
$id_array = array();
$selection = $this->input->post("selection", TRUE);
$id_array = explode("|", $selection);
foreach($id_array as $item):
if($item != ''):
//DELETE ROW
$this->db->where('cardno', $item);
$this->db->delete('paycust',$item);
endif;
endforeach;
}
.......
function logger_management()
{
....
}
[/quote]
Posted 11 January 2013 - 09:05 AM
Posted 11 January 2013 - 09:08 AM
Posted 11 January 2013 - 09:13 AM
1)what is "mainlog"?
[/quote]
here`sclass mainlog
[quote]
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MainLog extends CI_Controller {
function __construct()
{
parent::__construct();
/* Standard Libraries of codeigniter are required */
$this->load->database();
$this->load->helper('url');
/* ------------------ */
$this->load->library('grocery_CRUD');
}
public function index()
{
echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
die();
}
public function logger()
{
$this->grocery_crud->set_table('paycust');
$output = $this->grocery_crud->render();
$this->_example_output($output);
}
function _example_output($output = null)
{
$this->load->view('logger_template.php',$output);
}
}
/* End of file main.php */
/* Location: ./application/controllers/main.php */
[/quote]
Posted 11 January 2013 - 09:14 AM
Posted 11 January 2013 - 09:32 AM
This is a first project for you?
[/quote]
yes..this is my first project...i`m sorry if i ask a lot of question
Posted 11 January 2013 - 09:35 AM
Posted 11 January 2013 - 09:40 AM
Posted 24 January 2013 - 09:01 AM
<script type="text/javascript">
$(document).ready(function(){
$('input[type=checkbox]').click( function(){
if($(this).is(':checked')){
$('#qr-selected-item').removeAttr('disabled');
}else{
if(!$('input[name=custom_delete]').is(':checked')){
$('#qr-selected-item').attr('disabled','disabled');
$('.checkall').removeAttr('checked');
}
}
});
});
$(function () {
//CHECK ALL BOXES
$('.checkall').click(function () {
if($(this).is(':checked')){
$('#qr-selected-item').removeAttr('disabled');
}else{
$('#qr-selected-item').attr('disabled','disabled');
}
$(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
});
//ADD DELETE BUTTON
if($('.tDiv2 .qr_all_button').length == 0) { //check if element already exists (for ajax refresh purposes)
$('.tDiv2').append('<input id="qr-selected-item" type="button" value="Generate Qr" class="qr_all_button" onclick="qr_selected()" style="top: 0px";>');
$('#qr-selected-item').attr('disabled','disabled');
}
});
function qr_selected()
{
var list = "";
$('input[type=checkbox]').each(function() {
if (this.checked) {
//remove selection rows
//$('#custom_tr_'+this.value).remove();
//create list of values that will be parsed to controller
list += this.value + '|';
}
});
//send data to delete
$.post('http://localhost/cru...es/qr_selection' { selection: list }, function(data) {
//alert('QR Generated !');
});
}
</script>
<!-------------------------------------------------------------------------------------------------------------------------->
<script type="text/javascript">
$(function () {
//CHECK ALL BOXES
$('.checkall').click(function () {
$(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
});
//ADD DELETE BUTTON
if($('.tDiv2 .qr_all_button').length == 0) { //check if element already exists (for ajax refresh purposes)
$('.tDiv2').append('<input type="button" value="Generated Qr" class="qr_all_button" onclick="qr_selected();">');
}
});
function qr_selected()
{
var list = "";
$('input[type=checkbox]').each(function() {
if (this.checked) {
//remove selection rows
//$('#custom_tr_'+this.value).remove();
//create list of values that will be parsed to controller
list += this.value + '|';
}
});
//send data to delete
$.post('http://localhost/cru...es/qr_selection' { selection: list }, function(data) {
});
}
</script>
But it does not work due to Javascript, could you pls help me telling, how can i get ''save file dialog box'' when click on the 'Generate Qr' Button.
I tried using preventDefault() method but the button got invisible.
An attachment is given for your better understand.
I look forward to your early reply.
Thank You,
Suman