网格字段筛选功能咨询及Selector未同步更新问题求助
Hey there! Let's dig into your issue. First off, yes—you absolutely can filter fields within a grid in Acumatica—we just need to adjust your setup to get that Selector behaving as expected when you filter.
Looking at your code, the core problem is likely how the Selector is tied to the stateID value in the grid. When working with grid rows, the Current<stateID> reference might not reliably pick up the active row's value, especially after filtering. Here's how to fix it:
Step 1: Add AutoRefresh to the Selector
First, update your PXSelector attribute to include AutoRefresh = true. This tells Acumatica to automatically re-run the Selector's query whenever the linked stateID field changes (including when you filter rows in the grid).
Here's your modified code snippet:
#region CategoryID [PXDBInt()] [PXUIField(DisplayName = "Category ID")] [PXSelector( typeof(Search<PESKPriceIndexCat.categoryID, Where<PESKPriceIndexCat.state, Equal<Current<YourDACName.stateID>>, And<PESKPriceIndexCat.active, Equal<True>>>>), typeof(PESKPriceIndexCat.categoryID), typeof(PESKPriceIndexCat.categoryCD), typeof(PESKPriceIndexCat.descripcion), DescriptionField = typeof(PESKPriceIndexCat.descripcion), SubstituteKey = typeof(PESKPriceIndexCat.categoryCD), AutoRefresh = true // This triggers a refresh when stateID changes )] public virtual int? CategoryID { get; set; } public abstract class categoryID : PX.Data.BQL.BqlInt.Field<categoryID> { } #endregion
Note: Replace YourDACName with the actual name of the DAC that contains both CategoryID and stateID.
Step 2: Verify Your stateID Field Definition
Make sure the stateID field in your main DAC is properly defined so Acumatica can track its value changes. A basic example would look like this:
#region StateID [PXDBString(50)] // Adjust the data type to match your database setup [PXUIField(DisplayName = "State ID")] public virtual string StateID { get; set; } public abstract class stateID : PX.Data.BQL.BqlString.Field<stateID> { } #endregion
Step 3: Add a RowSelected Event (If Needed)
If the AutoRefresh alone doesn't fix the issue, you can force the Selector to refresh whenever a grid row is selected or updated by adding a RowSelected event handler to your Graph:
protected virtual void YourDACName_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { var currentRow = (YourDACName)e.Row; if (currentRow == null) return; // Refresh the CategoryID Selector based on the current row's StateID var categorySelector = cache.GetStateExt<YourDACName.categoryID>(currentRow) as PXSelectorState; if (categorySelector != null) { cache.ClearQueryCache<YourDACName.categoryID>(); cache.SetStateExt<YourDACName.categoryID>(currentRow, categorySelector); } }
This ensures that every time a row is loaded or selected, the Selector re-runs its query with the current row's stateID value.
Final Checks
- Make sure the
PESKPriceIndexCatDAC'sstatefield matches the data type of your main DAC'sstateIDfield (e.g., bothint?or bothstring). Mismatched types will break the filter. - Test filtering the grid by
stateID—the CategoryID Selector should now only show options wherePESKPriceIndexCat.statematches the row'sstateIDandactiveisTrue.
内容的提问来源于stack exchange,提问作者Tibu

