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


Add quick update button in view 1 / 0 value

callback_column add_action

  • Please log in to reply
10 replies to this topic

#1 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 09 February 2013 - 09:16 PM

Hi to all.

How can i add in the view quick update function for one row ?

 

DB structure:

ID primary auto increment

VALUE var_char

STATUS bolean 0/1

 

Default STATUS is NULL. I need in view update STATUS on select on of value 0/1 without open edit form.

 

123.png

 

Thanks in advance.



#2 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 10 February 2013 - 07:36 AM

you can use callback_column.

1) create radio buttons (first is activ, second is inactiv).
2) make a JavaScript function which will be listen events (in our case click by radio button) send to server a post request to update the row.

Or you can use link for that. It's more simply, because you can use url as data for Javascript function to send ajax request to  server.



#3 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 11 February 2013 - 12:08 PM

you can use callback_column.

1) create radio buttons (first is activ, second is inactiv).
2) make a JavaScript function which will be listen events (in our case click by radio button) send to server a post request to update the row.

Or you can use link for that. It's more simply, because you can use url as data for Javascript function to send ajax request to  server.

 

Privet Victor.

How can i do this with URL as data ?



#4 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 11 February 2013 - 12:18 PM

http://www.grocerycr...page/#entry5321 If you don't understand I can explain this in Russian

#5 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 13 February 2013 - 02:59 PM

Thank you  Victor for solution !

SOLVED by Victor.

 

function programs_management()
{
if ($this->input->get("status"))
   {
      ( //$this->input->get("status")=="1")?"1":"0");
      $data_for_update = array(
         'status' => ($this->input->get("status") == "y") ? "1" : "0",
      );
      $this->db->update('programs', $data_for_update, array('program_id' => $this->input->get("program_id")));

   }
}


function enable_status($value, $row = NULL)
{

if ($value == "1")
      return '<a href="' . base_url() . 'admin/programs_management/?status=n&program_id=' . $row->program_id . '" >Active</a>';
   else
      return '<a href="' . base_url() . 'admin/programs_management/?status=y&program_id=' . $row->program_id . '" >Inactive</a>';
}
 

 



#6 SiyaStoan

SiyaStoan

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 16 February 2013 - 03:04 PM

Thank you  Victor for solution !

SOLVED by Victor.

 

function programs_management()
{
if ($this->input->get("status"))
   {
      ($this->input->get("status")=="1")?"1":"0");
      $data_for_update = array(
         'status' => ($this->input->get("status") == "y") ? "1" : "0",
      );
      $this->db->update('programs', $data_for_update, array('program_id' => $this->input->get("program_id")));

   }
}


function enable_status($value, $row = NULL)
{

if ($value == "1")
      return '<a href="' . base_url() . 'admin/programs_management/?status=n&program_id=' . $row->program_id . '" >Active</a>';
   else
      return '<a href="' . base_url() . 'admin/programs_management/?status=y&program_id=' . $row->program_id . '" >Inactive</a>';
}
 

 

Hi TLC033

 

I would like to say Thank you for posting your solution. Thank you as well victor for the input. I'm new to PHP and looking to implement similar functionality on my app but I get a syntax error on Netbeans on the following line. may you please assist . Thanx

 

 ($this->input->get("status")=="1")?"1":"0");

 

 



#7 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 16 February 2013 - 03:33 PM

delete this string. This is mistake

#8 SiyaStoan

SiyaStoan

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 17 February 2013 - 08:36 AM

delete this string. This is mistake

 

Thanx Victor :) Worked 100%

 

How do I keep the user on the same page after clicking the cancel link, because at the moment it goes to another page?



#9 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 17 February 2013 - 11:08 AM

you can use that code in that function which show the grid. I'll share code which use Ajax as solution.

#10 SiyaStoan

SiyaStoan

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 17 February 2013 - 02:41 PM

you can use that code in that function which show the grid. I'll share code which use Ajax as solution.

 

Thanks again Victor :-) I added this line and it's all good.

 

redirect('main/booking_management', 'refresh');


#11 nungadi28

nungadi28

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 27 April 2018 - 03:21 AM

hello can i use this script from direct update db using 

TransaksiProject/?status=1&id_trans_project=' . $row->id_trans_project . 

this willupdate status from 0 to 1 right?







Also tagged with one or more of these keywords: callback_column, add_action

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users