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

Difficulty loading a data var from external .js file

3 Answers 164 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 17 Jan 2012, 03:03 PM
Hi!

I need to separate the datasource for my grid in a separate user updatable data file, called "datasource.js". 

I have placed the call to the src in the head and it fails totally in Komodo Edit. When I place the src call in the body, it works in Komodo, but not in the browsers (Opera and Chrome).

The data file looks like this:
var data = [{"picture": "EnviroPopulation99.png","TaxiName": "Andrew's Taxis","TaxiPhone": "01239 289617"},
{"picture": "Island Biogeography 99.png","TaxiName": "AllStar Taxis","TaxiPhone": "01249 241521"},
{"picture": "MarkandRecapture99.png","TaxiName": "TaxiCars","TaxiPhone": "01249 275141"},
{"picture": "Population Viability Analysis99.png","TaxiName": "01TaxiCabs", "TaxiPhone": "01249 275987"}];
var testdata = "Hello data!";

The code html file has the standard grid code calling data: data;

The test variable at the bottom of the file works fine.

Is there any reason why a data variable called from an external .js file using <script> would fail, please?

All the best,

Andrew.

3 Answers, 1 is accepted

Sort by
0
John DeVight
Top achievements
Rank 1
answered on 18 Jan 2012, 03:49 PM
Hi Andrew,

I've tried recreating the problem, but have been unsuccessful. 

Here is how I referenced the datasource.js:

<script type="text/javascript" src="/Scripts/datasource.js"></script>


Here is the code that I defined for the grid:

$('#peopleGrid').kendoGrid({
    dataSource: { data: data },
    columns:
    [{
        field: 'TaxiName',
        title: 'Taxi Name'
    }, {
        field: 'TaxiPhone',
        title: 'Taxi Phone'
    }]
});

How does this compare to what you have defined for your grid?

Regards,

John
0
Andrew
Top achievements
Rank 1
answered on 18 Jan 2012, 05:35 PM
Hi John!
Many thanks for giving this issue a go. I contacted Kendo Support and they looked at the complete code and reduced the <script> line to just that, no "text/javascript". They also addded a !DOCTYPE html command at the top. That's all as far as I could see.
Apparently different browsers expect to see slight variations in code so now it runs fine in Opera and IE.
Problem solved for me at least.

Cheers,
Andrew.
0
John DeVight
Top achievements
Rank 1
answered on 18 Jan 2012, 06:12 PM
Glad to hear =)

Regards,

John DeVight
Tags
Data Source
Asked by
Andrew
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Share this question
or