⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


multiple delete selection

checkbox multiple delete refresh

  • Please log in to reply
34 replies to this topic

#1 casachit

casachit

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 09 May 2012 - 03:25 PM

okay this is my first topic in this forum.. past few weeks i have enjoyed a lot using grocery crud...

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)

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,166 posts

Posted 09 May 2012 - 06:14 PM

Hello casachit and welcome to the forum.

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.

#3 KaBaDaBrA

KaBaDaBrA

    grocery CRUD magician

  • Members
  • PipPipPip
  • 57 posts

Posted 09 May 2012 - 07:52 PM

For your number 2 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:

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.

Attached File  list.php   4.02K   2912 downloads

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;
}


#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,166 posts

Posted 09 May 2012 - 09:23 PM

I think it will be quite easy for me to do it the only problem is that I haven't so much time for this. Except of real life groceries ...e.t.c.(KaBaDaBrA knows what I mean :) ), now I want to make available for the new version the "save and go back to list" button , the "unset_list" and "unset_back_to_list" functionalities that lot of users are expecting and lot of important bug fixes.

So please just be patient.

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.

#5 casachit

casachit

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 13 May 2012 - 03:09 AM

thanks a lot... both of you.... :) .. it helped me a lot.. for time being... I am now going to look for deeper to make it work in more appropriate way... thanks a lot again..

#6 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 09 November 2012 - 04:56 PM

Hi. KaBaDaBrA

THX. Work great.

#7 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 20 December 2012 - 08:14 AM

If somebody need this with enable/disable Delete Selected button.
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.

#8 phenom1711

phenom1711

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 11 January 2013 - 07:21 AM

For your number 2 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:

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.

Attached File  list.php   4.02K   2912 downloads

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;
}


why my data cannot be delete after i use function?

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('trxnum', $item);
          $this->db->delete('paylog');
          endif;
   endforeach;
}


here`s my code controller after i add that function

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());
}
}



#9 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 January 2013 - 08:23 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?

#10 phenom1711

phenom1711

    Newbie

  • Members
  • Pip
  • 5 posts

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?


1. sorry..i was change to

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;
}


2. so, how i must put that function?
3. yes..i was change it..

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 :)



#11 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

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 !');
		 });
}


#12 phenom1711

phenom1711

    Newbie

  • Members
  • Pip
  • 5 posts

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 !');
		 });
}

my url is

function delete_selected()
{
// ........
// change the url
                 $.post('<?=base_url();?>/index.php/mainlog/logger', { selection: list }, function(data) {
                                 alert('Deleted !');
                 });
}


not delete_selection. i was put this function into logger controller

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()
{
....
}



#13 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 January 2013 - 09:05 AM

1)what is "mainlog"?

#14 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 January 2013 - 09:08 AM

Your class called "Logger" and it has a function called "logger". It's a bad practice.

#15 phenom1711

phenom1711

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 11 January 2013 - 09:13 AM

1)what is "mainlog"?


here`sclass mainlog

<?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 */



#16 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 January 2013 - 09:14 AM

This is a first project for you?

#17 phenom1711

phenom1711

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 11 January 2013 - 09:32 AM

This is a first project for you?


yes..this is my first project...i`m sorry if i ask a lot of question :)

#18 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 January 2013 - 09:35 AM

I recommend you explore the basic functionality of the framework. Try to make for example blog without using third-party libraries.

#19 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 January 2013 - 09:40 AM

You call the function "logger". But this function doesn't delete your data.

#20 azsuman

azsuman

    Member

  • Members
  • PipPip
  • 16 posts

Posted 24 January 2013 - 09:01 AM

Dear KaBaDaBrA, I've used the above solution for multiple deletion and it's really work very fine. Now i've used this code to export selective data in a PDF file. The following is my code in list.php;

<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

Attached Thumbnails

  • qrcode.JPG






Also tagged with one or more of these keywords: checkbox, multiple delete, refresh

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users