Editing expanding ListGrids

Hi,

I have a fairly common use-case with grids (in fact, I’d have thought this is a fairly common use case generally, not just for me). I want to present the user with a list of items. The items can be edited, but the normal reason for accessing the list will be to add items to the bottom of it. I can achieve this with listEndEditAction: “next”, and then calling grid.startEditingNew().

However, this way of doing things allows users to leave rows blank - they can just keep pressing the down arrow and leaving a trail of empty records. Sure, I can say required: true and have it flag all those empty items as errors, but I’d rather just prevent them from leaving an empty row if doing so would take them into editing another new row. I also don’t necessarily want to show errors on the row they’re leaving - the error condition is that they’ve tried to start a new row without completing this one; the fact that they have not completed this row is not an error per se (indeed, it is quite normal - they have to stop adding lines some time!)

I’ve been playing with the rowEditorExit() function, and I’m sure I can get the behaviour I want with enough programming here, but it involves a lot of trial and error. I just wondered if there’s a simpler way to achieve this behaviour.

Thanks,

Wayne

Is that a no then?

Almost certainly a yes, actually. I’ll get back to you shortly on this one.

Here’s one approach: provide a rowEditorExit() override as follows:

isc.ListGrid.create({
    ...
    rowEditorExit : function (editCompletionEvent, record, newValues) {
        return isc.isAn.emptyObject(newValues) ? false : true;
    }
});

You can paste that function into the ListGrid definition on this example on the website to give it a quick try:

http://www.smartclient.com/#_Grids_Editing_Enter.new.rows

Will this work for you?

No. This technique prevents the user from moving off a grid row unless they change it, which isn’t what I want at all. What I want sounds quite specialised, but is really just common sense (for a given value of “common”, of course!)

I want users to be able to freely move amongst the existing grid entries, as long as those entries are valid. If they move off the last item, I want to present a new, empty item for editing. If they choose not to edit this last item (eg, because they didn’t really mean to move off the last item, or they didn’t realise that doing so would give them a new item), they should be free to abandon it and move back up the list entries above. It’s only if they try to move down off this item again, and thus create another new item, that I want to stop them, and preferably in a silent way rather than triggering a bunch of yellow triangles.

The reasoning behind this is that this grid is the very first my users will see. They will have no training, they’ll be coming in green, never having seen this application before, and it has to support their intuition because the setup screens are the shop-window for the entire system. If it allows them to create five empty items and then complains “You have created five empty items”, then I’ve probably just pissed somebody off - and I can’t afford to do that, because this is one of the earliest impressions my application will make.

I suspect the answer is that I’m going to have to do some specific programming around rowEditorExit. This is absolutely fine, I don’t have a complaint about it - I just wondered if there was a simpler way because it seems like a common requirement (for my value of “common”, of course!)

Thanks for your help so far

Your requirements seem perfectly reasonable. I actually thought we had a flag for something like this, but can’t find it at the moment. I’ll update if I do. In the meantime, the following is probably what you want:

    rowEditorExit : function (e, record, newValues, rowNum) {
        if (isc.isAn.emptyObject(newValues)) {
            // suppress creation of new row if we're navigating away from
            // an empty row
            if (e == "arrow_down" || e == "tab") {
                return false;
            } else if (e != "programmatic") {
                // navigating 'up' into an existing row from an empty row
                this.discardEdits(rowNum);
                return true;
            } 
        }
        return true;
    }

Give that a try and let me know what you think.