In my acumatica application, I created a custom page where the user needs to insert data in the grid section. In order to validate the provided data, I implemented the RowInserting and RowUpdating Events.
The problem is that in the rowinserting event I first throw an error using the following code:
cache.RaiseExceptionHandling<DZField.size>(fieldLine, fieldLine.Size,
new PXSetPropertyException(string.Format(ValidationMessages.FIELD_NOT_VALID_FORMAT,
"Size"), PXErrorLevel.RowError));
Then I set the e.Cancel property to true. But when the user changes the incorrect value and re-triggers the event, the row will have missing values which were not manipulated in the event.
I also tried to not set the e.Cancel property and instead throw a PXException, but even in this case other values in the row were reset.
In your RowInserting event, you are not throwing an error, you are raising it.
From documentation, the RowInserting event handler is used to:
Evaluate the data record that is being inserted.
Cancel the insert operation by throwing an exception.
Assign the default values to the fields of the data record that is being inserted.
If you use the throw syntax in a row inserting event, a popup window will appear with your error message and the record will not be visible in the grid. You shouldn't use e.Cancel for validations in RowInserting.
Example of cancelling insertion:
protected virtual void DACName_RowInserting(PXCache sender,
PXRowInsertingEventArgs e)
{
throw new PXException(ErrorMessages.FieldIsEmpty,
typeof(PaymentMethodAccount.paymentMethodID).Name);
}
Source: RowInserting Event
Regarding row updating, using e.Cancel for validations will cancel updating of all fields which are marked as dirty for that row. Sometimes that's what you want but based on your question I think that's something you want to avoid.
When validating individual fields you can use the field updating event which will not affect other fields or raise field exceptions. Throwing an error in a row event or setting e.Cancel in a row event will affect the whole row.
Related
I'm looking for the way how to implement RowUpdated event handler in Answers grid. I've implemented RowUpdated event handler in the value column of the grid but it doesn't work.
I want to concatenate the value of the attribute column value in the description field when I change the value from the drop-down list
Can anyone provide advice please?
protected virtual void CSAnswers_Value_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
}
Works fine on my instance, BUT event will be raised only if
Focus has been changed
Ctrl+Enter pressed
Which is fine from my standpoint. Do you really need to get an event right after the value changing?
Is there a way to hide an entire row, not just a single column, in a grid? I'm tried PXUIField.SetVisible, PXUIField.SetVisibility, PXUISetVisible, and PXUISetVisibility, but none of them seem to work. I know that using PXUIField.SetEnabled(cache, row, false) disabled the entire row, but can I make an entire row invisible?
You need to make sure the row is not returned in the query (could override the view delegate and not return specific rows) or removed from the cache. I don't think there is anything that can hide a row using the UI related calls, but I have never come across the need for this to ever try it.
The usual pattern is to use a PXFilter DataView current DAC record to filter the PXSelect DataView bound to the grid.
The filter fields are often changed on screen directly by the user but you can also set the value of the current filter DAC record programmatically in event handlers to build more complex logic.
public PXFilter<DACFilter> Filter;
public PXSelect<DAC,
Where<DACFilter.field, Equal<Current<DACFilter.fieldFilter>>>> GridDataView;
It appears to not be possible to programmatically select a specific value in the Kendo DropDownList element. I checked the API, but wasn't able to find something to trigger this.
There is a selectionChange event, but this is triggered by manually selecting a value from the dropdown. I'm interested in programmatically selecting an event; is there any way to do this?
Kendo does not take the new value unless we trigger the change event for the drop-down list. Once we set the value we have to trigger the change event
var menulist = $("#menulist").data("kendoDropDownList");
dropdownlist.value("Top");
dropdownlist.trigger("change");
Add the following to the dropdown html tag: (selectionChange)="selectionChange($event)"
And add the following to your typescript code:
protected selectionChange(value): void {
console.log("The current value is: " + value)
}
To change the selected item from the code behind, use this: http://www.telerik.com/kendo-angular-ui/components/dropdowns/api/DropDownListComponent/#toc-value
Is there any way to select a grid row from code so you can trigger the selectionChange event emitter? I don't know how to get hold of the grid component and execute the event manually.
Selection grid sample plunkr
<kendo-grid [data]="gridView" [selectable]="true"></kendo-grid>
--
Edit: If I access the grid manually by adding a #gridReference tag into the kendo-grid tag, I can access the component using
#ViewChild('activityGrid') gridReference: GridComponent;
But when executing
var selectionEvent = { index: 0, selected: false } as SelectionEvent;
this.gridReference.selectionChange.emit(selectionEvent);
It still doesn't work. It migth work when I have to access the SelectionService using unselect but that's a private class.
Updated plunkr
This could be achieved now by utilizing the new SelectionDirective. It allows specifying the key to be stored when selecting a row and also the selectedKeys collection to hold reference to the selected keys. This also allows to programatically modify the selection.
Unfortunately, currently it is not possible to select a row programmatically via the public API.
The selectionChange emitter is there to trigger the selectionChange event and I'm afraid it will not trigger the selection logic.
We have a view delegate and we are returning custom results according to the filters specified. Once the result is available the user choose any record, say 3rd and uses it. Next time they might change the filter criteria, and the view delegate returns a different set of result.
Here it seems the grid is auto selecting the record in previous position (3).
how can i reset the selection to the first record?
<View>.Current = <FirstRecordINeed>;
<View>.Cache.ActiveRow = <FirstRecordINeed>;
I have tried setting the activeRow/current in view delegate and the filter row updated event. But doesnt work. Any help?
To get ability to affect grid's ActiveRow you should specify property SyncPositionWithGraph="true" in the px:PXGrid in aspx.
After that you can set <View>.Cache.ActiveRow in the view delegate and it will affect grid.