Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderators: ArturoRobles, ArturoRobles

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#794620
Hello everyone,

What could be the best way to insert / delete a row in the middle of a Grid, when the add or delete options are disabled in a Grid for some reason?

I use the current method now:

For adding after row n:
a) Copy all rows of mygrid to tempgrid
b) Clear all rows of mygrid
c) Restore first 'n' rows from tempgrid into mygrid
d) Add a row in mygrid
e) Restore remaining rows from tempgrid into mygrid

For deleting row n:
a) Copy all rows of mygrid to tempgrid
b) Clear all rows of mygrid
c) Restore first 'n - 1' rows from tempgrid into mygrid
d) Restore remaining rows from 'n + 1' onwards from tempgrid into mygrid

Best wishes,
SGK
#794734
Your method appears the best to me in JavaScript. In PHP, you might try using this function with your grid variable:
Code: Select all
   function insert($array, $index, $val)
   {
       $size = count($array); //because I am going to use this more than one time
       if (!is_int($index) || $index < 0 || $index > $size)
       {
           return -1;
       }
       else
       {
           $temp   = array_slice($array, 0, $index);
           $temp[] = $val;
           return array_merge($temp, array_slice($array, $index, $size));
       }
   }
See: https://stackoverflow.com/questions/335 ... c-position

The 500 Internal Server Error is the general catch[…]

Really very nice blog information for this one and[…]

This is a long, lengthy and cumbersome process. T[…]

Great read for when on the road. The book provides[…]