Telerik Radgrid and filtering on ListTextField with a GridDropDownColumn

Another story in what it’s really like to develop software. These are the kinds of hacky bodges you will end up making in any system that is more than a few months old and is in production. 🙁 These hacks do not make me happy. Especially when they are hacked because of pre-built components that are meant to save you time!

The Telerik Radgrid is both a blessing and a curse at the same time. How can a grid, that seems designed to have a dropdown column in it and comes with default filtering, not take into account the fact that you are going to have foreign keys in a grid that you want to filter on?

This is an ongoing rant of mine. Getting good foreign key support on large enterprise applications seems like an uphill struggle every single time. I wrote about how I like to see books on programming jump right in and show me how to get my foreign key drop downs hooked up almost right off the bat, since it is almost entirely unavoidable in any application that has any sort of usefulness in my opinion.

My goodness getting the RadGrid to do your bidding can be an infuriating ride. Personally, I think components should just work out of the box. I know the RadGrid is extremely complex and there are layers upon layers of documentation and examples on the Telerik site, but to me, I shouldn’t have to find out about how difficult it is to filter on ListTextField after I’ve knocked up a prototyped to a client. Heck the documentation should have a large caveat at the top telling you the limitation of the software. Really, I shouldn’t need to read that far into the documentation just to use the component in my opinion. I want something quick and easy to take the pain out of grid based data admin, not a whole new bloody thing that I have to learn inside out.

As per Telerik’s website:

he built-in GridDropDownColumn will be filtered by its ListValueField when the default filtering feature of the control is used. Filtering by ListTextField is not attainable in the present version of Telerik RadGrid

Great. Thanks! This is burried in the How To section. Okay, not too obtuse, but still, all the basic examples show filtering on example datasets that are things like Customer listings (with Customer, Contact Name, Company). Heck, it is reasonable to assume that Company was being looked up using the GridDropDownColumn column. Isn’t it?

So, Telerik provide a solution – have a hidden field that is the text description. Capture the ItemCommand on the grid and then if it is a filter command, pop the filter text into the hidden field’s filter text box and run the filter based on that criteria. The problem is, out of the box this breaks user experience because the filter text they typed in disappears.

Now you have to hack around to find a way to keep the filter text there. Come on Telerik, get this one together. Not pleasant. I gave up, because I didn’t have time to delve that deeply into the RadGrid. I needed something quicker. Option 2 given by Telerik – implement a custom drop down in the actual filter area of the grid. The example code was long and I didn’t feel like going through it – again time constraints. I just couldn’t spend time exploring all of this because I have deadlines. Why couldn’t they just build this into the grid? If they have solutions, it shouldn’t be that difficult to put it into the base functionality.

One more thing – putting a drop down in that is based on an id field (and let’s be honest it probably is if it’s a lookup into another table) means you get the default “number” filtering options. This means that the filtering options out of the box are things like “greater than”, “less than” etc etc. These don’t make sense for a user who is filtering based on text. This is another fault with their default solution outlined above of using the hidden field and substituting values in. I know you can overide this and put your own filtering menu in, but say it with me…..deadlines. 🙁

By now, I’m not a happy bunny. What did I do in the end? I amended my stored proc to bring back a complete result set with description fields (making things slower for me because now I have table joins). Then I hid the drop down list field until the user wanted to edit the row or add a new row in. Then I hid the description fields and showed the drop down fields.

What a bodge.

Stupid SQL mistakes – more from the land of application support

Here’s a lovely little one that just took me much to long, probably because I’m tired, or having an off day or something:

Select [Name]
         [Surname],
         [Address],
         [Telephone],
         [Email]
From ATableAboutPeople

See, the error isn’t obvious, because the SQL compiles and runs, but the result set just doesn’t bring back what you expect…..because [Name] is now aliased as [Surname] – all because of a missing comma.

Hate it when that happens.

Rails on Windows – nil object when you didn’t expect it

If you jump between Linux and Windows XP like I do, sometimes you’ll pull your Rails app into the dreaded M$ platform, fire it up and be greeted with a lovely “Internal Server Error”. Naturally it goes on to say something like “You have a nil object when you didn’t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each” despite the fact that you’ve changed no code since last night when your app was running rather nicely in a Linux environment thank you very much. Sometimes you just need to hack your way out of a problem without worrying about the whys and wherefores – and that’s exactly what we are going to do here. So……open up configenvironmentsdevelopment.rb and find this line :

config.logger = Logger.new(config.log_path, 2, 10.kilobytes)

comment it out comme ca

#config.logger = Logger.new(config.log_path, 2, 10.kilobytes)

and fire it up again. All good? Yes? Excellent. Fixed. Why? Um. Log rotation in XP apparently. Something funny about it. Don’t really know. Haven’t investigated it much further because there is no way in hell I’m going to run a production Rails app in Windows. Ever.

Google charts + open government data == cool

Yes indeed folks, I bring you the number of passports lost or stolen in Europe as recorded by the British consulates in said countries for the year 01 April 2008 to 31 March 2009.

Red = worse. From which we can falsely infer that we shouldn’t go to the red ones because you are more likely to have your passport stolen 🙂

Hacking WordPress – how to show all comments with a custom quicktag

One of the blessings in WordPress is the vast array of plugins available. However, it is also one of the curses….because it makes us lazy. While this doesn’t seem to be problematic in the short term, in the longer term, large numbers of plugins can cause blogs to slow down, and even worse, the various plugins could start interfering with each other. So, whenever I can, I like to write my own code – the two advantages are that
1 – I can control exactly what goes in to the code, making it do what I need and no more
and
2 – I’ve written the code so if things start to clash, it’s going to be easier to debug.

So, let’s learn how to create a WordPress page to display every comment on our blog and just for fun, let’s also code up a quicktag which we can place into any page or post where we want the comments displayed.
Continue reading Hacking WordPress – how to show all comments with a custom quicktag

C# Dictionary object – know your database structure and I won’t have to hack like this

private Dictionary theThingThatWasNotUnique(){
  blah blah blah;
  Dictionary aSetOfResults= new Dictionary();
  foreach (DataRow dr in ds.Tables[0].Rows){
    DateTime startDate= (DateTime)dr["dtStart"];
    string activityName = (string)dr["sActivityName"];
    aSetOfResults.Add(startDate, activityName);
  }
}

The Dictionary object in C# is pretty neat. It’s fast and light because it’s essentially a hash table and it really is nice to enumerate through. The gotcha is, it relies on unique values in the key. And herein lies the problem with the code above. In the application I was troubleshooting, the dates that were stored were not guaranteed to be unique. This is really a simple case of not understanding the data structure properly and making false assumptions. Continue reading C# Dictionary object – know your database structure and I won’t have to hack like this

Learning Ruby on Rails- Drop Down Lists in One to Many Relationships

If you are just looking for some help without reading my rambling post……
the short answer is, collection_select – something like this:

<%= collection_select(:city, :country_id, @countries, :id, :country_name, {:prompt => false}) %>

not f.select as I did the first time round

<%= f.select('country_id', @countries.collect {|r| [h(r.country_name), r.id] }, { :include_blank => false }) %>

🙁

Continue reading Learning Ruby on Rails- Drop Down Lists in One to Many Relationships