Skip to main content

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;
}
}

 

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.


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.


FYI: For anyone that runs across this topic it just came to light that my last solution is still not working.  It “works” if I first deselect all on the screen but if we just de-select one or 2 and click Process, nothing happens and the individual de-selects are checked again.

I just asked the client if we could just go back to the default where the user just has to click the select all as this is just way too much trouble to try to change this behavior.  Thankfully they were good with this.  The grid is set to continuous scroll (vs. paging) so selecting all should get all the rows in the results.


Hi @rjean09 

We can achieve this with alternate solution. But not sure it will helpful for you. Try once.

  1. Create a new button “Select All”  above the grid or header level.
  2. Loop all the records and mark selected as true.

    Example :

      public PXAction<Carrier> selectAll;
            PXUIField(DisplayName = "Select All", MapViewRights = PXCacheRights.Select, MapEnableRights = PXCacheRights.Update)]
            PXButton]
            public virtual IEnumerable SelectAll(PXAdapter adapter)
            {  
                foreach (INSiteSelected site in PXSelect<INSiteSelected>.Select(Base))
                {
                    site.Selected = true;
                }
                return adapter.Get();
            }

Reply