mleibman/SlickGrid — pull request #243 by asavoy (2011-12-07 08:20:27+00:00)
Title: Fixed dataview filtering breaking, after compressing JS with e.g. Google Closure Compiler

### Background

We're using SlickGrid (it's *awesome*), and recently updated to latest. We found that after running our build scripts, which compress our JS files using Google Closure Compiler, our grids that used DataView filtering all broke.

### Cause

The problem is with the general approach that SlickGrid.DataView's ``compileFilter()`` and ``compileFilterWithCaching()`` use; that is, using ``Function.toString()`` to fetch original source code for ``fnTemplate`` and the user's filter function, to generate a new function.

The code relies on carefully named variables to act as targets for later string replacement. These will be shortened/changed by compressors, so the behavior ends up broken.

(The code also makes some pretty strong expectations about the style/structure of the user's filter function, which causes other issues... I will elaborate in a separate issue)

### Fix

To fix, I rewrote the function templates as strings, since it's only there so that the function body can be retrieved via ``Function.toString()``. This prevents them from being modified by a JS compressor. Unfortunately, the readability is penalised a little bit.

Furthermore, there isn't any workaround offered by Google Closure Compiler; there is no way to ignore or "not-compress" the code, whether at the function level or at the file level.

I hope this saves someone else hours of debugging...