#XAF #XPO How to add an Action that will display filtered detail collections in a separate ListView
Jakub Kosinski2 years ago
when i declare few class where one i parent with few childs in detail view i get tabs with child records. I.e customer and child records: orders, invoices , payments. I want to not display child views but want to add extra action for display it using Actions from ribbon
I find description how to display list view using action:
private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) { IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Invoice)); e.ShowViewParameters.CreatedView = Application.CreateListView(objectSpace, typeof(Invoice), true); }
but there i get all records, but i want only related to customer from DetailView. How to add this filtering ?
Leave a Comment
1 Solution
Andrey K (DevExpress Support)2 years ago
Hello,
To get an object that is currently selected in a view, use the View.CurrentObject property, to apply a filter to a created list view, use its CollectionSourceBase.Criteria property. So the code of your action can look as follows:
[C#]Open in popup window
private void simpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
var selectedContact =(Contact) this.View.CurrentObject;
IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(MyTask));
var listView= Application.CreateListView(objectSpace, typeof(MyTask), true);
listView.CollectionSource.Criteria["MyFilter1"]= new BinaryOperator("AssignedTo.Oid", selectedContact.Oid, BinaryOperatorType.Equal);
e.ShowViewParameters.CreatedView = listView;
}
To hide an item from a detail view, remove it from the "Views-YourNameSpace-YourClass_DetailView-Items" node's collection using Model Editor.
Let me know if you have any additional questions.
Thanks,
Andrey
Jakub Kosinski2 years ago
Thank for your reply.
But if i show new window with filter criteria, and try to add new record, then parent is not filled. How to add to this code to fill correct value. I know i can in dataModel set initial values when record is creating, but how to get there accessories to parent record ?
And one more question: how to force this created view to run in Server mode ?
Alex Gn (DevExpress)2 years ago
Hello Jakub,
You can modify the controller as follows:
[C#]Open in popup window
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model.NodeGenerators;
using MainDemo.Module.BusinessObjects;
namespace MainDemo.Module.Controllers {
public class OpenListViewController : ViewController<DetailView> {
private SimpleAction simpleAction1;
private void SimpleAction1_Execute(object sender, SimpleActionExecuteEventArgs e) {
IMemberInfo memberinfo = Application.TypesInfo.FindTypeInfo(typeof(Contact)).FindMember("Tasks");
string viewId = ModelNestedListViewNodesGeneratorHelper.GetNestedListViewId(memberinfo);
PropertyCollectionSource collectionSource = Application.CreatePropertyCollectionSource(ObjectSpace, typeof(Contact), View.CurrentObject, memberinfo, viewId, CollectionSourceDataAccessMode.Server, CollectionSourceMode.Normal);
var listView = Application.CreateListView(viewId, collectionSource, false);
e.ShowViewParameters.CreatedView = listView;
e.ShowViewParameters.TargetWindow = TargetWindow.NewWindow;
}
public OpenListViewController() {
this.TargetObjectType = typeof(Contact);
simpleAction1 = new SimpleAction(this, "OpenListView", "Edit");
simpleAction1.Execute += SimpleAction1_Execute;
}
}
}
The LinkNewObjectToParentImmediately property specifies the moment when a new object is added to the parent collection. By default its value is false and you need to commit the master object to save the link to a newly created object.
Let me know if you need any further assistance.