Grid Groupable column with null value, does not work

Oct 14, 2015 at 7:11 AM
Edited Oct 14, 2015 at 7:18 AM
I have used Grid and allowed to group columns. For columns which has values its working fine. But if i try to group any column which does not have value (or it has null value) then its not showing records even if server has returned the records.

Also we have used "ClientFormatFunc" for some of columns and passed an object to that function.

Any advise?
Oct 14, 2015 at 8:51 AM
what do you mean by column that has null value ?
Column.Bind is not defined
or an item (row) in the datasource has item.Food = null
Oct 14, 2015 at 9:37 AM
Yes an item in datasource has item.food = null
Oct 14, 2015 at 9:54 AM
maybe your query is filtering out those items,
tried it in the demo and it worked, only had to adjust the .Where(o => o.Food.ToLower() so I wouldn't get null reference exception ( o.Null.ToLower() )
Oct 14, 2015 at 10:07 AM
Could you please provide the sample?
Oct 14, 2015 at 10:12 AM
in the main demo Db.cs find this line
        var foods = new[] {"Banana","Cheesecake","Hot Beverage", "Brisket", "Oat meal", "French toast", "Pizza", "Apple Pie", "Shepherd's pie",
        "Salad", "Sushi", ""};
and add the "" as shown above
build and run
on home/index the first grid group by food

if you add null instead of "" you'll have to change the grid controller as well because of null.ToLower()
Oct 14, 2015 at 10:31 AM
changing null value to "" may not possible in my case as the sample that i have created has around 50 columns and checking and updating each column value is not feasible solution.

Is there any other approach?
Oct 14, 2015 at 10:35 AM
I was just explaining how to try this in the main demo
Oct 14, 2015 at 1:51 PM
Can we group if datasource column value is null for few of items?
Oct 14, 2015 at 2:29 PM
yes, you can try that in the demo as I explained above
Oct 15, 2015 at 10:15 AM
Edited Oct 15, 2015 at 10:16 AM
Ok,

Could you please try with making below changes and let me know if its working for you?

--In Index.cshtml set below for Grid1
new Column{Bind = "Location", ClientFormatFunc = "ShowLocation"},
where ShowLocation is a javascript function

--Update Db.cs for locations as below (last value is null)
var locations = new[] { "Home", "University", "Restaurant", "Visit", "Diner", "Central Perk", null };

--Group grid with column location.
This is what my scenario is, if its working at your end then i must be doing something wrong.
Oct 15, 2015 at 10:56 AM
you should be getting
Uncaught TypeError: Cannot read property 'toString' of null
in your browser console
this is actually fixed in dev version

but for now you need to make sure that ShowLocation func doesn't return null, so it could look like this:
function ShowLocation(model) {
    return model.Location || '';
}
Oct 15, 2015 at 10:58 AM
In browser console "model" itself is null. and i am having many client format functions, so i wanted to do a global code which will handle this issue.

Any idea?
Oct 15, 2015 at 11:02 AM
Edited Oct 15, 2015 at 11:03 AM
try this in the demo app first, after in your custom app,
if you're using ColumnsPersistence, remove it for now or click the grid reset button every time you change columns definitions
Oct 15, 2015 at 11:19 AM
yes tried in demo app, its giving below error in console:

http://s4.postimg.org/p32fi8dnx/grid_error.png
Oct 15, 2015 at 11:31 AM
Oct 15, 2015 at 11:51 AM
Yes, its working fine in code which you have given.

Will check whats an issue in my code and let you know.

Thanks for your support
Oct 15, 2015 at 6:18 PM
make sure you are using the latest version
Oct 19, 2015 at 11:16 AM
Hello,

It looks like you have completely modified your AwesomeMvc.js in latest version.

Earlier we could find the id generated for radio button or check boxes etc. in newer version its not at all generated.

//In earlier version
<li>
<input " +(d.S ? 'checked="checked"' : l) + 'id="' + a.i + "item" + b + '" name="' + a.v.data("name") + '" value="' + d.V + '" type="checkbox"/>
<label class="awe-label" for="' + a.i + "item" + b + '">' + d.T + "</label>
</li>

//latest version
u += '<li><label class="awe-label"><input type="' + i + '" value="' + o[0] + '" name="' + t.nm + '" ' + (o[2] ? 'checked="checked"' : "") + " />" + o[1] + "<\/label><\/li>"

We considered that id will be generated permanently with same format however you have completely changed it. Now for testing the app which we created has stopped working. I think its better to rollback newer updates and use earlier version. At run time we check the id of check box and radio buttons, so its not working with latest update.

Any advise?
Oct 28, 2015 at 6:20 AM
Edited Oct 28, 2015 at 6:23 AM
why do you need ids for each item ?

you can use mods in the new version
@(Html.Awe().AjaxRadioList("cat1")
        .Mod("myradiolist")
        .Url(Url.Action("GetCategories", "Data")))

<script>
    function myradiolist(o) {
        function render() {
            o.d.empty();
            var items = '';
            $.each(o.lrs, function (i, item) {
                var checked = $.inArray(item.K, awe.val(o.v)) > -1;
                items += '<li ><label><input type="radio" id="' + o.i + 'item' + i + '" value="' + item.K + '" name="' + o.nm + '" ' + (checked ? 'checked="checked"' : '') +
                    '" />' + item.C + '</label></li>';
            });
            var res = '<ul>' + items + "</ul>";

            o.d.append(res);
        };

        o.v.data('api').render = render;
        o.v.on('change', render);
    }
</script>
+ is plus
Oct 28, 2015 at 3:13 PM
Hi,

Thanks for your suggestion,

We have identified the problem and it was with "GroupHeader" null value.

We will have technical discussion once we purchase the license, as currently project is still in development phase.
Oct 28, 2015 at 4:52 PM
where exactly was the null value ? and how did it got there

also about the previous questions, since the id is generated using the value, you might as well select the item using [value=x] selector
Oct 29, 2015 at 6:55 AM
While preparing grid data we used custom header using "MakeHeader", for example:

return new GroupHeader
                    {
                        Content = name
                    };
Where sometime "name" value could go null, which is why it was failing.

For your second question, we have used earlier version (4.5.0.0) of "Omu.AwesomeMvc" assembly where i guess ".Mod" was not available and it was generating ids without doing anything.
We tried referencing latest library but due to some conflicts we reverted it back.
Oct 29, 2015 at 7:02 AM
what was the conflict/error message ?