This project is read-only.

Null value in column sorting

Jun 26, 2014 at 1:23 PM
Edited Jun 26, 2014 at 1:24 PM
I have found this thread:

Which gave me some ideas about printing NULL values in grid, but when I try to sort them I always get this error: System.NullReferenceException: Object reference not set to an instance of an object.

And I just can't figure out whats wrong(I'v tried doing same as in thread, but It didn't help)

How can I sort grid with null values?

My column. add line looks like:
columns.Add(model => model.Modelis.model_name).Sortable(true).RenderValueAs(model => model.Modelis == null ? string.Empty : model.Modelis.model_name); 
Jun 26, 2014 at 5:47 PM

I guess that your collection is loaded and grid try to sort collection using Linq To Objects, I am right?

If so you can determine a new property for displaying in hte grid:
        public string ModelName
                if (this.Modelis == null)
                    return string.Empty;
                return this.Modelis.model_name;
Then bind column to this property:
columns.Add(model => model.ModelName).Sortable(true)
Jun 30, 2014 at 7:25 AM
It works!

I wanted to ask, maybe it is possible to set get for such kind a variable:
    public virtual Class.CarModel Modelis { get; set; }
Since I will have a lot of propertys (~30 that might be nullable) to create and manage 30 more new variables is taking-time.