Skip to main content
Solved

Save only selected rows in grid


Forum|alt.badge.img

Hi Team,

Need to know how to save only selected rows records only. Can someone help me out?

 

Thanks

 

Best answer by jinin

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

View original
Did this topic help you find an answer to your question?

8 replies

Forum|alt.badge.img
  • Varsity I
  • 71 replies
  • October 10, 2023

Hi,

 

I would suggest,

Override the RowPersisting event for the lines, in there check to see if the Select box is ticked, if so call the base row persisting method, if not do nothing.

I’m not 100% sure if the do nothing piece will be sufficient to stop the save on the unselected lines.  You might need to do something to remove the lines you don’t want to save from the cache (within the row persisting event) or raise some kind of event.

 

Maybe have a go and share you code if your not getting the outcome you want?

 

JOhn

 

 


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 702 replies
  • October 11, 2023

Hi @bhagyat25 ,

As @JWS539  suggested use the Row persisting event or override the persist method and implement the logic. Loop all the records and if the select checkbox is marked as false, delete the line items from the grid.

 protected virtual void PrimaryDAC_RowPersisting(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            if (e.Row == null) return;

            foreach (DACName obj in ViewName.Select())
            {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }
        }
 


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 51 replies
  • October 16, 2023
jinin wrote:

Hi @bhagyat25 ,

As @JWS539  suggested use the Row persisting event or override the persist method and implement the logic. Loop all the records and if the select checkbox is marked as false, delete the line items from the grid.

 protected virtual void PrimaryDAC_RowPersisting(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            if (e.Row == null) return;

            foreach (DACName obj in ViewName.Select())
            {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }
        }
 

Hi @jinin ,

I tried your code but it is not working as I expected. record is moving to the deleted cache from the updated cache list. But still it is updating. 


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 702 replies
  • Answer
  • October 16, 2023

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 51 replies
  • November 28, 2023
jinin wrote:

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 702 replies
  • November 28, 2023
bhagyat25 wrote:
jinin wrote:

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Hi @bhagyat25 ,

This is the Save action override method. you can use the same code. and write logic inside..


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 51 replies
  • November 28, 2023
jinin wrote:
bhagyat25 wrote:
jinin wrote:

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Hi @bhagyat25 ,

This is the Save action override method. you can use the same code. and write logic inside..

Hi @jinin, I tried it too. But that method is not calling. In order to confirm that I put a break point in my visual studio project and put a break point and attached the running instance, But that method is not calling.

        [PXOverride]
        public void PersistMethod(Action del, PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            foreach (HMRCVendorRegisterDetail obj in VendorRegisterDetail.Select())
            {
                if (obj.UsrSelect == false)
                {
                    VendorRegisterDetail.Delete(obj);
                }
            }

            del();
        }


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 702 replies
  • November 28, 2023
bhagyat25 wrote:
jinin wrote:
bhagyat25 wrote:
jinin wrote:

Hi @bhagyat25 ,

Did u try the same logic with Persist override?

 [PXOverride]
 public void Persist(Action del)
 {
     foreach (DACName obj in ViewName.Select())
        {
                if(obj.Selected==false)
                {
                    View.Delete(obj);
                }
            }

            del();
        }

Hi @jinin,

How to call this method? Can you please tell me how to call this method in the graph?

Hi @bhagyat25 ,

This is the Save action override method. you can use the same code. and write logic inside..

Hi @jinin, I tried it too. But that method is not calling. In order to confirm that I put a break point in my visual studio project and put a break point and attached the running instance, But that method is not calling.

        [PXOverride]
        public void PersistMethod(Action del, PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)
        {
            foreach (HMRCVendorRegisterDetail obj in VendorRegisterDetail.Select())
            {
                if (obj.UsrSelect == false)
                {
                    VendorRegisterDetail.Delete(obj);
                }
            }

            del();
        }

 

public void PersistMethod(Action del, PXCache sender, PXRowSelectedEventArgs e, PXRowSelected baseEvent)

This is wrong

You should use like below(Check my sample above)

public void Persist(Action del) {
 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings