Skip to content

Filter items on the grid

New Discussion
Nikola Kalkovaliev
Nikola Kalkovaliev asked on Feb 21, 2020 9:26 AM

Hi guys,

I'm trying to filter (by default filtering via dropdown) a grid with multiple columns. My focus is on two columns. These columns consist of model which may contain another model inside, which we're not showing in the grid (rows). In the grid we only choose to show the first items that apply some of our applications demands. 

How do i apply filtering not just on the items that i see on the grid but also the ones that are there in the model dataset but we're not showing them on the grid?

Any solution and guidance would be really helpful.

Thanks

Nikola

Sign In to post a reply

Replies

  • 0
    Divya Jain
    Divya Jain answered on Feb 6, 2020 9:47 PM

    Hello Nikola,

    Thank you for posting. .I am not sure if I understand your requirement, having a filter for the columns which is visible in the grid would be simple ,refer to this online help doc : 

    But about the column which is not visible in the grid why do you need a filter for them?

    Thank you,
    Divya Jain

    • 0
      Nikola Kalkovaliev
      Nikola Kalkovaliev answered on Feb 6, 2020 11:01 PM

      Thanks for the initial input Divya.

      I'm interested in how can i filter items that aren't shown in the rows sections of the grid, but are part of the model that is shown in the grid. Due to requirements only a combination of items is shown in the grid while the others are now shown. Think of it as a Location that has multiple names but i only chose to show one location name on the grid (appropriate row). The other location names are there in the data model but hidden, not shown in rows on the grid.

      Can i filter by these values somehow from the drop down filter column even they are not shown on the rows grid?

      Thanks

      Nikola

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 7, 2020 2:09 PM

        There are a lot of different factors here to consider, and it's not really clear what you mean when you say data that exists in the model but not in the grid. Does the grid have columns for those fields that are simply hidden? Or have you somehow excluded them from the grid's DataSource entirely so the columns don't exist? 

        The filter dropdown for a column shows a unique list of values that exist in that column. So to use your example, suppose you have columns in your data source like street, city, and state, and you are hiding those columns and then using the InitializeRow event to build a string combining those three fields into an address. 

        So then you would want the user to be able filter by City, or State, and not the entire address? 

        Assuming the combined address is a string, the simplest way to handle that would be to show the FilterRow, make the operator visible, and then the user could pick Contains as the operator. So they could create a filter that would be something like "Contains Albany" or "Contains FL". Of course, this may not be ideal since the state abbreviation could be found inside other words within the address. But that would be the simplest approach. 

        Another approach would be for you to create your own custom filter conditions and add them into the dropdown list. So you could create a list of all of the States, for example, and then add those to the list, so the user would see whatever text you wanted like "State: NY" and then your custom filter condition would have to be coded to either parse the address from the combined string or else to look at the hidden field directly. This would require a lot more coding on your part, but it would be clearer to the user and more specific to the fields you have. 

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 8, 2020 1:05 AM

        Hi Mike 

        thanks for the info provided, i've decided to share a picture of the grid i'm working on.

        So here i'm trying to filter Collection Points and Delivery Points values that aren't shown on the grid. Here only one Collection point and one delivery point is shown. The load contains more that one of these values. So i'm adding those values into my custom Filter Conditions (the appear in the filter column drop down) and i call the FilterRow event and it works just fine (i add custom if state where i check if the filter selected is equal to the Collection value from the row, but if i filter the grid after that for let's say Trailer it doesn't filter the rows (the filter grid stays the same). I have checked the code this is because the filter row event is called for every filter called independently..One time it will be called for Trailer the other time it will be called for Collection and the third case is where is contains both the filters. So in theory it makes sense that it doesn't filter Trailers. But that's not what i want'. I want when i select some trailer value from the filtered out rows it filters them. I don't want the rows to stay the same (only collection point filter active, with values not show on the grid and with setting the filteredOutRow to false)

        Can u please give me some guidance on this?

        It would really help me.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 10, 2020 2:16 PM

        Hi, 

        I'm sorry, but your explanation of the issue still isn't making any sense to me. A lot of the terminology you are using doesn't seem right, and so I don't understand what you are trying to say.

        You say "Here only one Collection point and one delivery point is shown." But I am looking that the screen shot and clearly there are many values for each of these fields. So I don't understand what this means. 

        The FilterRow doesn't fire for each condition. It fires once for each row so that you can apply all of the filters. I suppose it could be firing when you add a single condition, and then firing again for each row when you add a second condition. That would make sense. The event would have to fire in order to evaluate the new filter conditions for each row. 

        I suppose it's also possible that FilterRow doesn't fire for explicitly Hidden rows. Your code in FilterRow should be setting e.RowFilteredOut. But if you were handling this event and setting the Hidden property on the row instead of using this property on the event args, then that might be permanently hiding rows instead of filtering them, which might mean that the event doesn't fire for those rows again. 

        It's also not clear what you mean by "custom filter conditions". You seem to be say that you are dropping down the list and choosing values, so those are not "custom" conditions. And if you are simply choosing values from the list, why are you handling the FilterRow event?

        Perhaps you could create a small sample project that demonstrates the behavior you are seeing so I could run it and try to see if I understand what's going on. But frankly, I'm still not really sure what you are trying to do here. 

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 10, 2020 3:56 PM

        Hi Mike,

        Thanks for the interest in my problem so in order to better understand it, i'll include pictures of the whole process:

        1. What we want is to filter columns (Delivery Point and Collection Point) and the rest of the columns of course.
        But with these two columns we also want to filter by Locations that are not viewed on the grid
        (as you can see on the picture i have selected Location that is not viewed on the grid.)
        The grid contains information for every Load which is different. But as i said we only show here on the grid
        1 Collection Point (Location) and 1 Delivery Point (Location), in the whole load there can be multiple of these but we only show 1-1.
        That's how the requirement is. Think of them as like this: LoadId = 1223876 we can have Collection Points (Dewsbury, Sunderland…) and also Delivery Points (Whitssely, Ibstok…)
        As u can see here on the picture i pointed out Ibstok. This location is not shown on the grid in any row but is part of LoadId = 1223905.
        How it got there? Well i added it via e.ValueList.ValueListItems.Add(filter.FormattedLocation) where "e" is BeforeRowFilterDropDownPopulateEventArgs event.

        2. What we want is that when we select this value the grid (rows) will be filterred accordingly. Currently if i select it, the grid rows are empty since i guess it's value is not "viewed" on the grid rows.

        After i have done here some implementations of my own like:
        – register FilterRowEventArgs
        – there i get the filter selected value with:
        FilterConditionsCollection deliveryColumnFilters = e.Row.Band.ColumnFilters[_colDeliveryPointKey].FilterConditions;
        – Convert it to string "deliveryNameFromFilterRow"
        – Compare the deliveryNameFromFilterRow with the current row that FilterRow event is checking.

        Here's the code.
        if (rowDs.MovementsDeliveryLocationNames.Any(x => x.Contains(deliveryNameFromFilterRow)) && !string.IsNullOrEmpty(deliveryNameFromFilterRow) && !e.Row.IsFilteredOut)
        {
        e.RowFilteredOut = false;
        }
        This works nice and it filters the row that i want.Here's the result (filtered by Ibstok Delivery Point location)

        My problems begin when i select another filter let's say Driver. It kinda excludes him since the rows stay the same. Here i filtered first by delivery point location and after that by Driver 2947. No change nothing. Like i didn't triggered the Driver filter. It's problem lays in the if statement above and that setting of e.RowFilteredOut.Can u please advice some approach on this problem? And i hope it's clearer now with the pictures attached.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 11, 2020 2:34 PM

        Hi, 

        Okay… I think we are making progress here, but there are still some things I don't understand. 

        So I am looking at your first screen shot and I see the rows in the grid. Now… you have selected a filter from the dropdown list, but the value you selected does not exist in any of the rows of the grid. So why does row 1223905 display in the grid? It doesn't match the filter you chose. 

        So I am trying to understand the code you have in the FilterRow event, but it's difficult because I don't know what many of these variables are.

        'rowDs' would seem to be the data source row – so you are getting that from the ListObject property of the grid row? So presumably that is examining the underlying data row and looking at a field/column that you are hiding from the grid? 

        It's also tough to see what's happening here because this looks like it's just a small snippet of the code in the event. But your 'if' condition seems like it might be incorrect, because you are checking '!e.Row.IsFilteredOut'. That means that if the row was not already filtered in, you won't even look at it. 

        It seems like you are trying to mix the grid's handling of filtering with your own, but if you are handling FilterRow, you have to handle ALL of the conditions. I don't think you can just handle some and not others. 

        If I understand all of this correctly, then all you really want here is – when the user selects something from the list, you want that condition to operate on a field that is not visible to the user – either because it doesn't exist in the grid, or because it's in a hidden column in the grid. 

        If that's the case, then I think maybe the FilterRow even is not the best way to go. What you could do instead is use a custom FilterCondition class. Right now, you are handling BeforeRowFilterDropDownPopulate and you are adding your own items into the list. You are specifying the DataValue of those items as filter.FormattedLocation, which is presumably a string. 

        What you could do, instead, is create a class that derives from FilterConditoin and overrides the MeetsCriteria method. You MeetsCriteria implementation would then examine the row and return true or false depending on whether the hidden field for that row matches the FormattedLocation.

        When you add the items to the ValueList, instead of passing in a string, you would pass in an instance of your custom FilterCondition as the value and then a string as the DisplayText.

        This way, the grid would combine the conditions correctly. 

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 11, 2020 9:27 PM

        Hi Mike 

        I think we're on a good path since i also started doing some implementation of a custom FilterCondition class. However where should i put the MeetsCriteria method? inside the FilterRow event or maybe i should try with AfterRowFilterChangedEventArgs event. Also when u said "our MeetsCriteria implementation would then examine the row and return true or false depending on whether the hidden field for that row matches the FormattedLocation.", i noticed that MeetCriteria accepts UltraGridRow row as a param. How my custom filter string "FormattedLocation" would come here into the method itself? 

        Thanks 

        Nikola 

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 11, 2020 11:06 PM

        Hi Mike i put on a solution that might work 🙂 it needs more testing, i'll let you know definitely about the outcome. So far looks good to me. Your directions helped a lot.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 12, 2020 2:19 PM

        Just to clarify… you need to create your own class which DERIVES from FilterCondition. Then you override the MeetsCriteria method. 

        In that method you only need to evaluate the one filter for the column against the row. There are properties on the FilterCondition itself that will tell you which column to use and what the filter criteria is. So something like this. Of course, you would need to write code to get the ListObject from the row, find the additional field you want to examine, and compare that against the compareValue, which you would presumably set to filter.FormattedLocation when you create the MyFilterCondition instance and add it to the Filter DropDown ValueList.

        public class MyFilterCondition : FilterCondition
        {
            public override bool MeetsCriteria(UltraGridRow row)
            {
                var column = this.Column;
                var compareValue = this.CompareValue;       
                
        
                return base.MeetsCriteria(row);
            }
        }

        There's also a ComparisionOperator property on the FilterCondition, but in this case, you probably don't care about that and will just ignore it. 

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 12, 2020 10:15 PM

        Hi Mike 

        thanks for the detailed assistance, Here's my implementation:

        public override bool MeetsCriteria(UltraGridRow row)
        		{
        			
        			var passedOutString = CompareValue.ToString();
        			string columnSelected = this.Column.ToString();
        
        			try
        			{
        				ViewLoadsEntity rowDs = row.ListObject as ViewLoadsEntity;
        				if (rowDs.MovementsDeliveryLocationNames.Any(x => x.Contains(passedOutString)) && columnSelected.ToString().Equals("DeliveryPoint"))
        				{
        					return true;
        				}
        
        				if (rowDs.MovementsCollectionLocationNames.Any(x => x.Contains(passedOutString)) && columnSelected.ToString().Equals("CollectionPoint"))
        				{
        					return true;
        				}
        
        				return false;
        				
        			}
        			catch (Exception)
        			{
        				return true;
        			}
        		}

      • 0
        Mike Saltzman
        Mike Saltzman answered on Feb 13, 2020 1:59 PM

        Looks good. So you are basically searching two fields in the data source, that are not necessarily in the grid, and if the row matches either of them you show that row, otherwise, you filter it out. 

        I'm still not 100% sure I understand what your goal is here, but if I am correct, that seems like exactly what you want. And that should work when combined with other filters since the code is isolated to just this one filter condition and no other. 

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 13, 2020 2:33 PM

        Yes it's in testing now but looks good so far. Yes that's exactly what a wanted. My first implementations with Filter Row event messed up the things a bit and as i said only one filter was working at a time. If you combined two of them the second added was basically not used.

        Thanks once again. will finish testing by eod and see if everything is fine. So far it's really nice and working as i wanted.

      • 0
        Vasya Kacheshmarova
        Vasya Kacheshmarova answered on Feb 21, 2020 8:55 AM

        Hello Nikola,

        Please let us know if you need any further assistance with this matter.

        Thank you for using Infragistics components.

      • 0
        Nikola Kalkovaliev
        Nikola Kalkovaliev answered on Feb 21, 2020 9:26 AM

        Hi Vasya

        No that's all, the help from Mike really did the job. I've done with the filters what i wanted.

        Thanks.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Nikola Kalkovaliev
Favorites
0
Replies
15
Created On
Feb 21, 2020
Last Post
6 years, 1 month ago

Suggested Discussions

Created by

Created on

Feb 21, 2020 9:26 AM

Last activity on

Feb 21, 2020 9:26 AM