slGrid: Edit Mode without Add or Delete

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.

Write a Comment

Comment

  1. If you change this
    if ($this->mode == MODE_EDIT)
    for this
    if (($this->mode == MODE_EDIT)&& ($this->editmode_add))

    you don’t need to comment everything!!

  2. …or you read the Doku:

    SetEditModeAdd(boolean is_enabled)
    Use this function on MODE_EDIT. You can decide if it should be possible to add rows. Sometimes you want to limit this possibility.
    SetEditModeEdit(boolean is_enabled)
    Use this function on MODE_EDIT. You can decide if it should be possible to edit a row.
    SetEditModeDelete(boolean is_enabled)
    Use this on MODE_EDIT. You can decide if it should be possible to delete rows.

  3. Hello Fetuline,

    I’m already aware of those options, however the problem is that they don’t functionally change the grid in a way that makes it usable in Edit mode without Add or Delete.

  4. Hi Raam,

    This is somehow the only place that i can found information related to slGrid online, although the post itself is already over 3 years old. I wonder why such a useful tool dont get much attention than this.
    Anyhow, I am having troubles getting the editing function to work properly. I did a clean install, the deleting function works, but however the update and add function doesn’t work. I can edit inline, but when i click the button on the table, nothing happened and when i refresh the page, all values returned to the original state.
    Do you have any suggestions that i can try?

    thanks so much for the help in advance~~

    best,
    p

    • Hi Phil,

      I wish I could help, but I haven’t used slGrid in many years. It also appears the original developer is no longer supporting slGrid, so I’m not sure where to point you. You could try asking for help on a PHP or Javascript forum… they might be able to help.

      Good luck!

      • Thanks Raam!
        If i may boldly be a little pesty here and ask one more question, do you know any other package like slGrid that would allow inline editing of MySQL tables. I am lost in google search…

        thanks again,
        P.

        • Hi Phil,

          I don’t know of any other web-based MySQL table editors, but if you search Google for “php mysql table editor”, you’ll find a couple of options! 🙂