Skip to main content

Telerik Grid and Dynamic filtering


Well let me say this is a tale of solving a problem for an existing system with poor test coverage.  Ok no test coverage.  No I didn't write it.  But yes I have to enhance it.  It isn't badly done code.  I mean there are places it could be improved.  Things I would have done differently.  New shining technologies we could and would use if it is was being done again but all in all it is straight forward and clean.  But it has no working tests, no comments.  I want to modify this code with minimal changes to minimize my risk and move on to more interesting things.  Oh did I mention the front end is built around Telerik.  You either love them or hate them.  For me it just depends on the problem but I usually just avoid them.

Nice term what does it mean....

A grid with filtering drop downs:

We want the filter drop downs with no selected filter value to filter the available options to only available choices based on other filters.



I assumed this would be an easy enhancement.  I just was not sure exactly the best way to do it.  But after more time then I care to admit too and a few path deviations, I came to the conclusion it was going to be harder than I thought.  Maybe some ajax calls after a filter selection or something else.

Well during my stage of coming to terms with what needed to be done, I stumbled across the FilterExpression property on my MasterTableView: grd.MasterTableView.FilterExpression.

OMG!!!

It has exactly what I want.  The where clause for the data being displayed in the grid.

Some more google searches but not much luck on a clear example.

Well I am familiar with Linq.  I have written in the past Dynamic expression code.  This could be what I want.  Now I remember the Dynamic Expression code being a pain to write so I need to dig up all code.  But rather than dig it up I try that Nuget search thingy.  ChaChing, someone has put it together for me.  I don't even have to dig it up.  DynamicQuery is the name and it look usable.

10 minutes later.....

On my drop downs filter Init function.

Pseudo code follows:



//Get the filter expression
string expression = grid.MasterTableView.FilterExpression;
if (expression != string.Empty && !expression.Contains("AreaId"))
                    {
                        var rst = GridRep.GetAllItems()
                             .AsQueryable()
                             .Where(expression)
                             .Select(
                               x => new Area() { SubsystemID = x.AreaID, Name = x.AreaName })
                             .Distinct().OrderBy("Name");
                        rcb.DataSource = rst;
                    }
                    else
                    {
                        rcb.DataSource = AreasRep.GetAllAreas();
                    }

Now that for me this is a simple low impact solution.  Notice the Where extension from the awesome DynamicQuery assembly.  I am using the expression right from the grid.  Maybe not the most efficient solution but low impact and easy to understand.

A shout out to Linq Goodness, Nuget and my fellow community of internet coders: You guys are great!

Cheerio!!!

Comments

Popular posts from this blog

Garage Door opener replaced

Our garage door opener has become intermittent, it has to go. It turned into a bit of a research project. We ended up installing a belt drive unit. The bracket was kind of a pain. It is suppose to be much more quiet. I started wearing gloves more for household projects. I love these gloves. Foam Nitrile Coated gloves. Check them out. I got them here. http://www.hardworkinggloves.com/index.php?main_page=product_info&cPath=3_13&products_id=120 Later...

Microsoft loses i4i appeal, faces Word injunction in three weeks

I just finished reading this article and it grinds on me. I cannot speak to the details of this patent but on the surface it looks to me like many software patents. They fail on the Non-Obvious test. Maybe it is because I understand software but what amazes me is far different from my wife who is in the medical field and even further from those I meet who are less educated. This does not even come close to impressing me!! I am not a M$ groupie as they have many unworthy patents too. The patent system is broke in this this area as well as others. This is not Dave over Goliath. It is Dave leveraging a broken system over Goliath. The same system Goliath leverages to maintain competitive advantages. Wrong is Wrong even when Dave does it. You can read it here... http://www.betanews.com/article/Microsoft-loses-i4i-appeal-faces-Word-injunction-in-three-weeks/1261523600
I saw how to do this on but the information was out of date. Download and install diffmerge. I used this link:  DiffMerge . Verify you can run it from the command line: Run the following commands from the git command line git config --global diff.tool diffmerge git config --global difftool.diffmerge.cmd 'sgdm "$LOCAL" "$REMOTE"' git config --global merge.tool diffmerge git config --global mergetool.diffmerge.cmd 'sgdm --merge --result="$MERGED" "$LOCAL" "$(if test -f "$BASE"; then echo "$BASE"; else echo "$LOCAL"; fi)" "$REMOTE"' git config --global mergetool.diffmerge.trustExitCode true Now use the standard git commands for launching diffs and merges git difftool filename.ext git difftool branchname filename.ext git mergetool Note:  I had to perform these steps twice.  Once running the git command line under admin and once under user.  ...