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

error/bug in foriegn key column

2 Answers 56 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.
mahmoud
Top achievements
Rank 1
mahmoud asked on 22 Apr 2012, 08:41 AM
Dear Teleriks , 
I have a simple scenario for filtering via foreign key columns . 
my column is defined as this

columns.ForeignKey(o => o.Sender, GetUsers(), "Value""Text");


where Sender is String , and the GetUsers() is defined as follows : 

@functions{
 
    List<SelectListItem> GetUsers()
    {
        return ((IEnumerable<ProfileCommon>)ViewBag.UserProfiles).Select(option => new SelectListItem
        {
            Text = (option == null ? "(none)" : option.ToString()),
            Value = option.UserName,
        }).ToList();
    }
}

The grid renders correctly (it means there is no any error in GetUsers() function) but in client-side when I click on the filter icon , nothing happened and in Chrome console I see the following error : 

4telerik.grid.filtering.min.js:1Uncaught TypeError: Cannot read property 'key' of undefined
  1. telerik.grid.filtering.min.js:1Uncaught TypeError: Cannot read property 'key' of undefined
    1. b.filtering.implementation.createFilterCommandstelerik.grid.filtering.min.js:1
    2. b.filtering.implementation.createFilterMenutelerik.grid.filtering.min.js:1
    3. b.filtering.implementation.showFiltertelerik.grid.filtering.min.js:1
    4. e.extend.proxy.gjquery-1.7.1.min.js:2
    5. f.event.dispatchjquery-1.7.1.min.js:3
    6. f.event.add.h.handle.ijquery-1.7.1.min.js:3


I couldn't find the source of problem after hours ! I would be appreciated if someone here can help me.

2 Answers, 1 is accepted

Sort by
0
jan
Top achievements
Rank 1
answered on 04 Jun 2012, 02:21 PM
Dear mahmoud,
I got the same exception.

The problem was that I didn't have keys "FilterForeignKeyEq" and "FilterForeignKeyNe" in my grid localization resources. See http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-localization.html to understand Telerik localization.

In telerik.grid.filtering.js, line 49:
$.each(this.localization, function (key, value) {
var prefix = 'filter' + (column.data ? "ForeignKey" : column.type);
var index = key.indexOf(prefix);
if (index > -1)
filters.push({
key: key.substring(index + prefix.length).toLowerCase(),
value: value
});
});
Did not find the key and line 61 fired exception:
if (column.type == "String") {
// put the ends with value last
if (filters[0].key !== "eq") {
Uncaught TypeError: Cannot read property 'key' of undefined
filters.push(filters.shift());
}
}


0
mahmoud
Top achievements
Rank 1
answered on 05 Jun 2012, 01:45 PM
Thanks!
I changed my solution after nothing found for the problem. I should check your solution to see it but I think you should be correct because I don't have the mentioned items in my resource file.
Tags
Grid
Asked by
mahmoud
Top achievements
Rank 1
Answers by
jan
Top achievements
Rank 1
mahmoud
Top achievements
Rank 1
Share this question
or