⚠ 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

Add quick update button in view 1 / 0 value



tlc033

tlc033
  • profile picture
  • Member

Posted 09 February 2013 - 21: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.


victor

victor
  • profile picture
  • Member

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.


tlc033

tlc033
  • profile picture
  • Member

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 ?


victor

victor
  • profile picture
  • Member

Posted 11 February 2013 - 12:18 PM

/topic/1284-custom-action-control-without-going-to-another-page/#entry5321 If you don't understand I can explain this in Russian

tlc033

tlc033
  • profile picture
  • Member

Posted 13 February 2013 - 14: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>';
}
 

 


SiyaStoan

SiyaStoan
  • profile picture
  • Member

Posted 16 February 2013 - 15: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");

 

 


victor

victor
  • profile picture
  • Member

Posted 16 February 2013 - 15:33 PM

delete this string. This is mistake

SiyaStoan

SiyaStoan
  • profile picture
  • Member

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?


victor

victor
  • profile picture
  • Member

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.

SiyaStoan

SiyaStoan
  • profile picture
  • Member

Posted 17 February 2013 - 14: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');

nungadi28

nungadi28
  • profile picture
  • Member

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?