Changing the Field Name

Aug 3, 2010 at 12:00 PM

Hi byKinag,

                     I have a requirement where I have to keep the Field name as Employee ID but in your control it picks up the field name as is from DomainData Source, can we add a property so that we can possibly Map field Names , for example we can have a property where we can say like this.

DataFilterControl.MappedFields = "ID=Employee ID,Name=Employee Name,Salary = Annual Income"

Some thing like above, one solution could be using alias in our SQL queries but as we have already created SQL queries its not possible to make changes Now, So If you can Help or Suggest me any solution for this I can do in the existing code, this feature is very much required as without it I we wont be able to use this control in my project as My project manager says that how the user will know which fields he needs to filer,sort or group on as the text what we give to our datagrid header does not match to the field name of the datasource( field name = ID and datagrid Header = Employee ID),

Thanks

Ahmed Kapasi

Coordinator
Aug 3, 2010 at 6:03 PM
Hi Ahmed. I also had this idea, but for not it is the demand has been delayed, do not be a problem. I will say more than that, in your existing project to make a change to not have to, because now we can use an existing opportunity for naming the column, look at "RIA Services -> DisplayAttribute" class and his Name member: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28SYSTEM.COMPONENTMODEL.DATAANNOTATIONS.DISPLAYATTRIBUTE%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22%29;k%28DevLang-CSHARP%29&rd=true
Coordinator
Aug 3, 2010 at 6:22 PM
Edited Aug 3, 2010 at 6:24 PM
implementing this functionality, I partially realized your recent issue on display collections of filters depending on the type of column, but the question still hangs in the air, because There are questions about implementation.
Coordinator
Aug 3, 2010 at 7:45 PM
suggestion is implemented, but partially, look at this for details: http://riadatafilter.codeplex.com/Thread/View.aspx?ThreadId=209039
Aug 4, 2010 at 7:49 AM

Hi byKinag,

                            Sorry but I coundn't understand how to use RIA Services -> DisplayAttribute class to solve my issue for displaying the field name as required, can you explain a bit more , do u mean to say that this functionality is already there and you don't have to change anything in this control ?  please let me know your reply .

 

Thanks

Ahmed Kapasi

Coordinator
Aug 4, 2010 at 8:53 AM

Hi

sorry for that, look at updated yesterday sample.

about DisplayAttribute look at server project metadata class.

Aug 9, 2010 at 10:17 AM
Edited Aug 9, 2010 at 10:18 AM

hi bykinag,

                 Thanks for the sample  , but DisplayAttribute won't help me as we have scenarios where we can use the same field with two or more different name like for the field Salary we might use it as "Salary" in some module and  "Annual Income" or "Annual Payment" in other modules, so how should I handle it in such cases. As alway waiting for your quick reply and solution.

Thanks

Ahmed Kapasi

Coordinator
Aug 9, 2010 at 5:56 PM

Hi Ahmed,

i try to add field names as collection.

Aug 10, 2010 at 9:38 AM

Hi bikinag,

                         I found a problem in the last sample you uploaded , though it picks up the Display Name properly from Metadata file but once you select the field name and do the lost focus from Field Name dropdown it shows the actual fieldname and not the name you have mentioned in the Display Attribute of the Metadata file , please look into this issue as the changes you have made wont solve the purpose unless this issue is there.

Thanks

Ahmed Kapasi

Coordinator
Aug 10, 2010 at 1:48 PM

Hi Ahmed,

about "problem" that you found i talking here:

http://riadatafilter.codeplex.com/Thread/View.aspx?ThreadId=209039

Aug 10, 2010 at 2:52 PM
Edited Aug 10, 2010 at 2:52 PM

Hi bykinag,

                        Thanks for your reply , so is that mean we no solution fort this issue as of now ?

 

Thanks

Ahmed Kapasi

Coordinator
Aug 10, 2010 at 3:48 PM
yes, currently i don't have idea how to do that. but I remember about this issue and as soon as I can implement this functionality, it will appear.
Aug 11, 2010 at 11:51 AM

Hi bykinag,

                            After you have changed the code to show DomainEntityField in the field name dropdown , it is showing the name space System.Windows.Controls.Data.DomainEntityField , instead of showing actual field name, can you look into this issue ASAP.

Thanks

Ahmed Kapasi

Coordinator
Aug 11, 2010 at 12:54 PM

Hi Ahmed,

yes you are right,

i fix that,

but not upload the new version of binary file,

because waiting your reply about error at another thread.

Aug 11, 2010 at 4:11 PM

Hi bykinag

                              Add this replace your OnDataGridFilterPreparingCellForEdit with the following code and then Check.

private void OnDataGridFilterPreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
        {
            switch (e.Column.DisplayIndex)
            {
                ////Initialized dgcFilterPropertyPath DataGridTemplateColumn.CellEditingTemplate
                case 0:
                    if (e.EditingElement.GetType() == typeof(ComboBox))
                    {
                        ComboBox element = e.EditingElement as ComboBox;
                        if (element != null)
                        {
                            element.SelectionChanged -= this.OnFilterPropertyPathComboBoxSelectionChanged;
                            element.ItemsSource = this.ListOfDomainEntityFields;
                            element.DisplayMemberPath = "DisplayName"; //Added by Ahmed 
                            element.SelectedValuePath = "PropertyPath"; //Added by Ahmed
                            if (this.dgFilter.SelectedItem != null)
                            {
                                element.SelectedItem = this.ListOfDomainEntityFields.Where(r => r.PropertyPath == (this.dgFilter.SelectedItem as FilterDescriptor).PropertyPath).FirstOrDefault();
                            }
                            element.SelectionChanged += this.OnFilterPropertyPathComboBoxSelectionChanged;
                        }
                    }
                    break;

                ////Initialized dgcFilterOperation DataGridTemplateColumn.CellEditingTemplate
                case 1:
                    if (e.EditingElement.GetType() == typeof(ComboBox))
                    {
                        ComboBox element = e.EditingElement as ComboBox;
                        if (element != null)
                        {
                            element.SelectionChanged -= this.OnFilterOperationComboBoxSelectionChanged;
                            element.ItemsSource = this.ListOfFilterOperationNames;
                            if (this.dgFilter.SelectedItem != null)
                            {
                                element.SelectedItem = this.ListOfFilterOperationNames.Where(r => r == Utilities.GetLocalizationByFilterOperator((this.dgFilter.SelectedItem as FilterDescriptor).Operator, this.FilterOperatorLocalizationCollection).ToString()).FirstOrDefault();
                            }
                            element.SelectionChanged += this.OnFilterOperationComboBoxSelectionChanged;
                        }
                    }
                    break;
            }
        }

Coordinator
Aug 11, 2010 at 6:18 PM
Hi Ahmed, thanks for your patch, but DisplayMemberPath is exists at the generic.xaml (i move it from theme to the code, like that do it you) and SelectedValuePath is not needed, because i use SelectedItem and cast it to the DomainEntityField
Aug 12, 2010 at 1:27 PM
Edited Aug 12, 2010 at 1:30 PM

Dear bykinag,

                                 I have an Idea where we display the displayname in the field name column of the dgfilter control, what we can do is on add click of the datafilter control 

we will add values in a new class named as DataFilterGrid class which has following properties

1) NameField = will be a string type and will Hold the DisplayName value of the DomainEntityField class

2) OperatorField = will be type of  FilterOperator and will hold the value for the operator

3) ValueField  = will be of string type an will hold the value what user will enter in the value field

and we in the Itemsource of the dgfilter will assign this class instead of assigning FilterDescriptors class

so our AddFilterItem() method will look like the code below.

 private bool AddFilterItem()
        {
            bool result = false;
            List<FilterGrid> FilterGridList = new List<FilterGrid>();
            if (this.FilterDescriptors != null &&
                this.ListOfDomainEntityFields != null &&
                this.ListOfFilterOperationNames != null &&
                this.ListOfDomainEntityFields.Count > 0 &&
                this.ListOfFilterOperationNames.Count > 0)
            {
                this.FilterDescriptors.Add(new FilterDescriptor(this.ListOfDomainEntityFields[0].PropertyPath, Utilities.GetFilterOperatorByLocalization(this.ListOfFilterOperationNames[0], this.FilterOperatorLocalizationCollection), string.Empty));
                FilterGridList.Add(new FilterGrid { NameField = this.ListOfDomainEntityFields[0].DisplayName, OperatorField = Utilities.GetFilterOperatorByLocalization(this.ListOfFilterOperationNames[0], this.FilterOperatorLocalizationCollection), ValueField = "" });

                //this.dgFilter.ItemsSource = this. ;
                this.dgFilter.ItemsSource = FilterGridList;
                result = true;
            }
            return result;
        }

Coordinator
Aug 12, 2010 at 4:56 PM

Hi Ahmed,

thanks for your reply.

 

i think about this class too.

 

this is a lot of work and before I start,

I need to make sure that these changes will not bring problems in the future work,

then I will implement it.

 

still waiting your screenshot about errors at another thread...

Aug 12, 2010 at 7:22 PM
Hi bykinag, Thanks for your reply , I have worked on it and currently what I have done is I have used a separate filterdescriptioncollection object for binding the dgfilter datagrid and in this collection I have binded the displayname and not the propertypath and in clearfilter method I remove filters from this new filter collection and so it reflects on the dgfilter grid also, I guess I am near to what I needed. and regarding the error screen shot can you pls give me any of your email ID where I can send you the pic , as in my office they we have no permission to access the photo sharing sites. Thanks Ahmed Kapasi
Sep 20, 2010 at 1:22 PM

dear bykinag,

                           Have you implemented the User friedly fieldname logic also in the latest code as we had discussed in this thread I mean can I pass the field names as a

control's property or I have to put the name as the DisplayAttribute in the metadata file only.

 

Thanks

Ahmed Kapasi

Coordinator
Sep 20, 2010 at 1:31 PM

you have two solution:

1) define names at your businnes layer class (DomainService at the server side, metadata class);

2) define names at the xaml or codebehind with using DomainEntityFieldCollection of the control (details look at documentation);

Sep 20, 2010 at 2:23 PM

Hi

    So is it possible to add the DomainEntityFieldCollection  at runtime or it should be only added at design time.

for example can we code like below.

FilteControl.DomainEntityFieldCollection  = ObjDomainEntityFieldCollection;

Thanks

Ahmed Kapasi

Coordinator
Sep 20, 2010 at 2:32 PM

yes you can add items at runtime from codebehind,
DomainEntityFieldCollection is auto initialized at control, you just need to add or remove items.