Hi everybody,
Is it possible to control the editability of certain records in a List/TreeGrid based on their content? I have not seen anything like that in the showcase.
What I’m doing now is call cancelEditing() from an EditEntryHandler when a row is hit which is by its data not editable. This has some ugly side effects, mainly that when I cursor down into a non-editable row and then cursor down again the grid attempts to edit the previously edited record instead of the new one below the non-editable record.
Any suggestions on this?
Thanks,
Andre
I pulled this out of the SmartClient documentation:
Editability of cells
Editors will either be shown for the complete row or for a single cell based on editByCell,editByCell. Whether a cell can be edited can be controlled on a per field basis by setting field.canEdit, or on a per-record basis by setting recordEditProperty on a record, or can be controlled on an arbitrary, programmatic basis via an override of ListGrid.canEditCell().
Cells which are not editable just display the cell’s current value.
I’m not sure how you would set that property on a ListGridRecord but you can definitely override canEditCell in SmartGWT.
Benjamin
You can use the ‘_canEdit’ property / attribute on a ListGridRecord. And if you prefer a different property, call ListGrid.setRecordEditProperty
/**
* Property name on a record that should be checked to determine whether the
* record may be edited.<br>This property is configurable to avoid possible collision with
* data values in record. With the default setting of "_canEdit", a record can be set non-editable
* by ensuring record._canEdit == false.010 <br> For controlling editability for the entire grid or
* for a field, set grid.canEdit or field.canEdit.
* <p><b>Note : </b> This is an advanced setting</p>
*
* @param recordEditProperty recordEditProperty Default value is "_canEdit"
*/
public void setRecordEditProperty(String recordEditProperty)
Note that all the SmartClient documentation has been pulled into SmartGWT javadocs under the com.smartgwt.client.docs package. The section on editing can be found here
Perhaps a dumb question:
Are attributes and properties interchangeable? It seems in this case they are (calling setAttribute would be equivalent to setProperty on a widget), is that true in all cases?
Benjamin
There are equivalent but there’s a subtle difference. setAttribute called on a widget before it is rendered simply sets a “config” property which is then used when the widget is actually rendered. Calling setAttribute after the widget is rendered calls setProperty which essentially is equivalent to calling a method on the widget to apply the change.
A very few properties are not changeable after the widget has been rendered and these can be identified in the javadocs as well as the method signature : “throws IllegalStateException”
Make existing records read-only
I have a listgrid that loads with existing records from a DataSource.
I want to be able to remove these records from the grid, and be able to add only new records, and I only want these new records to be editable, but the others which were originally loaded to not be editable.
I have done some research on this, and it seems I can make records non-editable. So, if record_.canEdit dfaults to true is fine, how and when do I change this? Do I do this in my DataSource Class? BTW, it is a GWT-RPC data source so do I create a DataSourceBoolean Field and add _canEdit=false to those records? Would that be how I default this?
Lastly, when I do create a new row, only two of the three fields will be editable.
Thanks!
Tom