Solved

Default Selected column to true on page load after rows populated

  • 12 November 2021
  • 5 replies
  • 46 views

I have a custom processing screen and the client wants the Selected column to be checked by default so users can just uncheck the rows they do not want to process. I’ve gently suggested they can just click the checkbox in the column header to select all with one click but that apparently is not acceptable for them.  The filter defaults so that rows are populated on page load.  I tried creating a view delegate and for loop to set the Selected column and this appears to work but has a side effect that it doesn’t detect the last one they’ve unchecked unless they click on another row so they’ve had some rows get processed unintentionally.  

.

        protected virtual IEnumerable detailsView()
{

PXView select = new PXView(this, true, DetailsView.View.BqlSelect);
Int32 totalrow = 0;
Int32 startrow = PXView.StartRow;
List<object> res = select.Select(PXView.Currents, PXView.Parameters, PXView.Searches,
PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startrow, PXView.MaximumRows, ref totalrow);
PXView.StartRow = 0;

foreach (PXResult<PX.Objects.AP.Standalone.APQuickCheck> row in res)
{
PX.Objects.AP.Standalone.APQuickCheck check = (PX.Objects.AP.Standalone.APQuickCheck)row;
check.Selected = true;
DetailsView.Cache.Update(check);
}

return res;
}

Again, the view delegate sort of works but has some nasty side-effects.  Any other ideas?  I tried using RowSelecting but couldn’t get that to work either.

 

        protected void APQuickCheck_RowSelecting(PXCache cache, PXRowSelectingEventArgs e, PXRowSelecting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);

var row = (PX.Objects.AP.Standalone.APQuickCheck)e.Row;

// default to selected upon reading from database
if (row != null)
{
row.Selected = true;
}
}

 

icon

Best answer by rjean09 16 November 2021, 15:33

View original

5 replies

Userlevel 3
Badge

In the DAC could you set the default for the Selected field to true?

In the DAC could you set the default for the Selected field to true?

Actually tried this first but that default only works when adding a new row, not when fetching records from the database.

Userlevel 7
Badge +10

Hi @rjean09  I can able to do this by updating the Selected field value in the View Delegate and worked for me successfully.

The only I see the difference from your view delegate is you have returned the result but I did with yield return for each record.

Here is the sample code for reference.

foreach (SOShipment ObjSOShipment in ResultQuery.Select())
{
DACName ObjImport = cmd.Select(ObjSOShipment.ShipmentType, ObjSOShipment.ShipmentNbr).FirstOrDefault();
ObjImport.Selected = true;
ViewName.Cache.Update(ObjImport);
yield return ObjImport;

}

 

Hi @rjean09  I can able to do this by updating the Selected field value in the View Delegate and worked for me successfully.

The only I see the difference from your view delegate is you have returned the result but I did with yield return for each record.

Here is the sample code for reference.

foreach (SOShipment ObjSOShipment in ResultQuery.Select())
{
DACName ObjImport = cmd.Select(ObjSOShipment.ShipmentType, ObjSOShipment.ShipmentNbr).FirstOrDefault();
ObjImport.Selected = true;
ViewName.Cache.Update(ObjImport);
yield return ObjImport;

}

Same problem:  “this APPEARS to work but has a side effect that it doesn’t detect the last one they’ve unchecked unless they click on another row so they’ve had some rows get processed unintentionally.”

 

Solved.  I moved the logic that sets Selected = true to APQuickCheck_RowSelecting:

protected void APQuickCheck_RowSelecting(PXCache cache, PXRowSelectingEventArgs e, PXRowSelecting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);

var row = (PX.Objects.AP.Standalone.APQuickCheck)e.Row;

// default to selected upon reading from database
if (row != null)
{
row.Selected = true;
}
}

I still have the detailsView delegate because I always want the data loaded from the database on a refresh or parameter change so that the RowSelecting is fired.  But all it does now is the select, not the for loop.  I think when I realized I needed the view delegate to fire the RowSelecting before I must have re-factored thinking I could do it all in the view delegate, but that’s what caused the problem.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2020  Acumatica, Inc. All rights reserved