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

[Solved] missing name after . operator

2 Answers 14 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.
David Kirkland
Top achievements
Rank 1
David Kirkland asked on 21 Jul 2011, 05:04 PM
Hi,

I am binding the columns of a grid to a value on an array object. The grid renders fine, but I get a javascript error:
missing name after . operator
    return data.[0].Value;

@model IEnumerable<PivotRow>
@(Html.Telerik().Grid<PivotRow>(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(o => o[0].Value).Format("{0:0}").Width(50).Title("0");
        columns.Bound(o => o[1].Value).Format("{0:0}").Width(50).Title("1");
        columns.Bound(o => o[2].Value).Format("{0:0}").Width(50).Title("2");
        columns.Bound(o => o[3].Value).Format("{0:0}").Width(50).Title("3");
        columns.Bound(o => o[4].Value).Format("{0:0}").Width(50).Title("4");
        columns.Bound(o => o[5].Value).Format("{0:0}").Width(50).Title("5");
        columns.Bound(o => o[6].Value).Format("{0:0}").Width(50).Title("6");
        columns.Bound(o => o[7].Value).Format("{0:0}").Width(50).Title("7");
        columns.Bound(o => o[8].Value).Format("{0:0}").Width(50).Title("8");
        columns.Bound(o => o[9].Value).Format("{0:0}").Width(50).Title("9");
        columns.Bound(o => o[10].Value).Format("{0:0}").Width(50).Title("10");
        columns.Bound(o => o[11].Value).Format("{0:0}").Width(50).Title("11");
        columns.Bound(o => o[12].Value).Format("{0:0}").Width(50).Title("12");
        columns.Bound(o => o[13].Value).Format("{0:0}").Width(50).Title("13");
    })
    .Pageable(pageable => pageable.Enabled(false))
)

The source for PivotRow can be found here:
http://vitamink.googlecode.com/svn/trunk/src/VK/Pivot/PivotRow.cs
(and this class contains the .Value property: http://vitamink.googlecode.com/svn/trunk/src/VK/Pivot/PivotData.cs)

I'm using the latest version of telerik (including jquery-1.5.1.min.js)

Thanks in advance!

David.

2 Answers, 1 is accepted

Sort by
0
David Kirkland
Top achievements
Rank 1
answered on 22 Jul 2011, 01:54 PM
I think the problem is caused by binding to an object indexer, however I thought that the Grid was able to bind to indexers and properties. As I said, the data renders properly, but I still get the JavaScript error.

columns.Bound(o => o[0].Value).Format("{0:0}").Width(50).Title("0");
0
David Kirkland
Top achievements
Rank 1
answered on 26 Jul 2011, 04:42 PM
So I found the answer in the file "telerik.grid.min.js". I don't know javascript well so my solution is a hack that I think will break other working code.

There is a portion of the javascript starting:
return new Function("data","return data"+(l.member?"."+l.member:"")+";")

which I changed, by removing "."+, to:
return new Function("data","return data"+(l.member?l.member:"")+";")

So it's not enough to check if l is a member. If the member itself is an array then the "." should be omitted, as it's a syntax error to refer to an array like this:
return data.[0].Value;

The correct syntax would be:
return data[0].Value;

As I already said, I am not an expert in javascript, so I don't know the solution. But I will attempt to find a fix which down't break existing code.




Tags
Grid
Asked by
David Kirkland
Top achievements
Rank 1
Answers by
David Kirkland
Top achievements
Rank 1
Share this question
or