I've been customizing slGrid for an application I'm developing at work. One of the things I needed to do was to enable the MODE_EDIT but at the same time prevent additions or deletions.
To prevent deletions, there is an option in /classes/gridclass.php
called $editmode_delete
, which you can simply set to false
to prevent deletions and remove the 'Delete' column. However, this creates another problem: While editing a row, the 'Delete' button and the 'Cancel' button share the same column:
So by disabling deletions, we're giving up our 'Cancel' button. This means the only way to get out of edit mode after clicking the 'Edit' button, is to refresh the page. OK, so thats not the end of the world. Lets continue.
Our next problem is insertions -- we need to prevent users from adding new rows. I saw the $editmode_add
option in /classes/gridclass.php
, and assumed it would be as simple as changing it to false
. But to my surprise, that only removed the 'Add' button, leaving the entire (empty) insertion row at the top of the table:
Well that doesn't make any sense. If there is an option to disable insertions, why leave the unused empty row? After lots of digging I finally found the block of code that needs to be commented/removed to prevent the empty row from loading:
gridclass.php:
if ($this->mode == MODE_EDIT) { $insert_row = array(); $row_index = -1; foreach ($this->columns as $column) $insert_row[$column->name] = ""; $this->CreateRow($insert_row, $row_index, $visible_row_index, $table_main); $row_index++; }
After commenting out that block of code, I finally have what I want; slGrid in Edit Mode without the ability to Add or Delete:
I'm going to be working with slGrid a lot now and I'll be tweaking/customizing it quite a bit. I will be sure to share everything I learn here on my blog for others who may wish to use it.