⚠ 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 is an archived forum. ⚠

  •     

profile picture

multiple delete selection



casachit

casachit
  • profile picture
  • Member

Posted 09 May 2012 - 15: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)

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 May 2012 - 18: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.

KaBaDaBrA

KaBaDaBrA
  • profile picture
  • Member

Posted 09 May 2012 - 19:52 PM

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

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 09 May 2012 - 21: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.([member='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.

[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.

casachit

casachit
  • profile picture
  • Member

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..

tlc033

tlc033
  • profile picture
  • Member

Posted 09 November 2012 - 16:56 PM

Hi. KaBaDaBrA

THX. Work great.

tlc033

tlc033
  • profile picture
  • Member

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.

phenom1711

phenom1711
  • profile picture
  • Member

Posted 11 January 2013 - 07:21 AM

[quote name='KaBaDaBrA' timestamp='1336593177' post='1684']
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]

victor

victor
  • profile picture
  • Member

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?

phenom1711

phenom1711
  • profile picture
  • Member

Posted 11 January 2013 - 08:32 AM

[quote name='victor' timestamp='1357892612' post='5031']
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]

victor

victor
  • profile picture
  • Member

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

phenom1711

phenom1711
  • profile picture
  • Member

Posted 11 January 2013 - 08:54 AM

[quote name='victor' timestamp='1357893597' post='5033']

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]

victor

victor
  • profile picture
  • Member

Posted 11 January 2013 - 09:05 AM

1)what is "mainlog"?

victor

victor
  • profile picture
  • Member

Posted 11 January 2013 - 09:08 AM

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

phenom1711

phenom1711
  • profile picture
  • Member

Posted 11 January 2013 - 09:13 AM

[quote name='victor' timestamp='1357895111' post='5035']
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]

victor

victor
  • profile picture
  • Member

Posted 11 January 2013 - 09:14 AM

This is a first project for you?

phenom1711

phenom1711
  • profile picture
  • Member

Posted 11 January 2013 - 09:32 AM

[quote name='victor' timestamp='1357895694' post='5038']
This is a first project for you?
[/quote]

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

victor

victor
  • profile picture
  • Member

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.

victor

victor
  • profile picture
  • Member

Posted 11 January 2013 - 09:40 AM

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

azsuman

azsuman
  • profile picture
  • Member

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