This is a migrated thread and some comments may be shown as answers.

[Solved] MVC Grid JavaScript Error filtering nullable columns

5 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gary
Top achievements
Rank 1
Gary asked on 23 Oct 2012, 12:17 AM
Hi all
I am using 2012 Q2 (2012.2.607) code for my first MVC 3 app.  I have a grid that operates in client mode.  When the grid is loaded, there are several columns ( mix of string, datetime and int ) that pull from nullable entities in the database using EF.

If all rows in the grid happen to be populated for the column, it filters and sorts OK.  If not, and the underlying data represents a null value, the sort is quite jumbled and the filter can throw an error in the telerik.common.js script:

"Microsoft JScript runtime error:  Unable to get value of the property 'indexOf': object is null or undefined.".

I tested one of the string columns by substituting a "" for the null value when the entity is queried, and that seems to fix the error for that column.  Do I really have to ensure there is a non-null value specified for every cell to ensure the grid sort/filter will work?

Thanks for any suggestionsGary

5 Answers, 1 is accepted

Sort by
0
Gary
Top achievements
Rank 1
answered on 24 Oct 2012, 10:04 PM
Further info here.  I was able to resolve the problem with the string columns by adding explicit Getters within my model class that set the data value to an empty string instead of null.  Looks like that may have fixed the javascript error. 

However, sorting and filtering still does not work with nullable dates. 
I did find some interesting behaviors, though.  If I have a sparsely populated DateTime? column, the sort appears to work OK until a row with a missing value is encountered. 

i.e. Assume I have 3 rows with date values, then 2 rows missing dates, then 3 more rows with dates.  The sort will correctly re-order the first three rows, then leave two rows with no values, then start over and sort the final 3 rows.  The rows containing values are not grouped together, and the intervening missing values throw off the sort.  Only within the sets of adjacent date rows is the sort working.

Also if I filter the sparse date column to something like "mydate comes after 1/1/2000", the filter works and the rows with missing column values are removed.  Then a subsequent sort on the remaining rows work fine, as there are no missing values.
 
Every MVC grid example I can find online has completely populated date columns.  Sounds like core functionality to allow for missing data?  Any support around for those of use not yet in Kendo-land?
0
Vassilis
Top achievements
Rank 1
answered on 26 Nov 2012, 02:04 PM
Gary, I'm facing a similar problem. Have you found a satisfactory solution?
0
Gary
Top achievements
Rank 1
answered on 26 Nov 2012, 03:17 PM
I did find a work-around, but hardly satisfactory.  For date columns, I used the explicit Getters in the view class to set the null dates to Date.MinValue.  I then added some client side code via jQuery to detect and hide these values in the grid.
The columns appear to sort correctly, with "missing" dates being treated as minimal values.  The filters are still only partially usable - operations like "Contains" are still not working even on string columns.

Not the kind of functionality I had hoped for from a Telerik grid.

Best of luck, let me know if you find a better solution?
0
Vassilis
Top achievements
Rank 1
answered on 30 Nov 2012, 10:40 AM
I used the getters for setting null to String.Empty for string properties. NUllable DateTime properties work ok for me in the grid sorting and filtering. It was the string ones that I had a problem with.

I'm using Q1 2012 SP1 (2012.1.419) and MVC 3, although I hardly think it's a version issue, that in my case Dates sort and filter ok Also, string filtering is working fine for me, with e.g. "Contains". Perhaps you are not using Nullable DateTime properties?
0
Gary
Top achievements
Rank 1
answered on 30 Nov 2012, 04:15 PM
No, V, all my datetime values are nullable.  Interesting that you do not see the same issue.  Are you using Client mode?

The relevant bits of my grid definition are as follows.  Does it differ significantly from yours?

.DataBinding(x => x.Ajax().OperationMode(GridOperationMode.Client))
.DataKeys(keys =>
           {
               keys.Add(k => k.myKeyID);
           }
  )
.ClientEvents(cl => cl.OnDataBound("onDataBound"))
.Scrollable()
.Sortable()
.Pageable(paging => paging.PageSize(100))
.Groupable()
.Footer(true)
.Reorderable(reorder => reorder.Columns(true))
.Resizable(resizing => resizing.Columns(true))
.Filterable()
Tags
Grid
Asked by
Gary
Top achievements
Rank 1
Answers by
Gary
Top achievements
Rank 1
Vassilis
Top achievements
Rank 1
Share this question
or