Set records initially as "edited"?

Is there a way to set all records in a grid as having already been “edited”?

Reason being that, I want to be able to validate a grid that starts off with empty rows and require the user to enter in values for all cells. But if they don’t enter any data and simply hit a save button, which triggers the .saveAllEdits(), there will be no “edited” records to validate. I’m just using the standard “required: true” validation.

I’ve tried looking for solutions and trying out the setEditValues but can’t seem to get the desired effect.

Thanks

Hi dleung,

You want listGrid.startEditingNew(). You can’t bring a new, unsaved record into existance by calling setEditValues(), but startEditingNew will do so.

Sorry, I actually meant that the grid does have records from the database, it’s just that they’re all initially empty. So, they’re not new records per se. So it essentially starts off as a grid with rows that have primary keys and empty column values for the rest of the row.

Ah, I see.

SmartClient assumes that anything loaded from the database is already valid and does not need validation applied. However if you call setEditValues() for each of the fields you’d like to have validated, passing the empty string or some other placeholder value like “[enter data here]”, the grid will behave as though the user had entered those values and will perform validation normally on save.

Note the properties for controlling the timing of validation, eg, validateByCell.

The thing about setEditValues() that concerns me is if a record actually does have data (yes, I did ask about initially empty cells.. that was the main concern). I don’t want to default every cell as an empty edited cell.

However, I saw showEmptyMessage and that would do exactly what I need if I could set those same cells as “edited” as well. Would there be any way of overwriting that to do so?

Hi dleung,

You can use setEditValues() to provide any value as the edit value and that value will be displayed in the cell - it doesn’t have to be blank. It can even be the exact value already shown in the cell.

The emptyMessage is something entirely different, for use when the grid has no records at all.

If setEditValues() somehow doesn’t solve your problem, you can always use formatCellValue to render anything you want for edited cells.

Sorry, I meant emptyCellValue. I’ll try and see if I can get setEditValues but I was having a difficult time iterating through rows.