I am puzzled at how to get this working properly. Have looked at many different ways but unable to get my jsGrid to load properly.
- Java SpringBoot
2.7.18
- Tomcat Embedded
- jsGrid
1.5.3
- jQuery
3.2.1
I have a js-grid-helper.js which has static information for the columns:
export var TABLE_COLUMNS = [
{ name: 'column_1', title: 'Column 1', type: 'text'}
,{ name: 'column_2', title: 'Column 2', type: 'text'}
,{ name: 'column_3', title: 'Column 3', type: 'text'}
];
I import this into my page.js and then reference it in my jsGrid initialization
import {
TABLE_COLUMNS
} from "../components/jsgrid-helpers.js";
$('#my-table').jsGrid({
width: '100%',
height:'700px',
filtering:true,
editing: false,
paging: true,
autoload: false,
sorting: true,
pageLoading: true,
pageSize: 20,
controller: jsGridController,
fields: TABLE_COLUMNS,
rowClick: function(args){
},
onDataLoading: function(args){
},
onDataLoaded: function(args){
}
});
I get an error for the following, because TABLE_COLUMNS is undefined
jsgrid.min.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at new d (jsgrid.min.js:7:30218)
at jsgrid.min.js:7:3982
at r.map (jquery-3.2.1.min.js:2:3309)
at d._initFields (jsgrid.min.js:7:3882)
at d._init (jsgrid.min.js:7:3131)
at new d (jsgrid.min.js:7:200)
at HTMLDivElement.<anonymous> (jsgrid.min.js:7:22224)
at r.each (jquery-3.2.1.min.js:2:2715)
at r.fn.init.each (jquery-3.2.1.min.js:2:1003)
at b.fn.jsGrid (jsgrid.min.js:7:22040)
d @ jsgrid.min.js:7
(anonymous) @ jsgrid.min.js:7
map @ jquery-3.2.1.min.js:2
_initFields @ jsgrid.min.js:7
_init @ jsgrid.min.js:7
d @ jsgrid.min.js:7
(anonymous) @ jsgrid.min.js:7
each @ jquery-3.2.1.min.js:2
each @ jquery-3.2.1.min.js:2
b.fn.jsGrid @ jsgrid.min.js:7
(anonymous) @ page.js:199
However, if I place the TABLE_COLUMNS in the SAME file it works absolutely fine like so:
var TABLE_COLUMNS = [
{ name: 'column_1', title: 'Column 1', type: 'text'}
,{ name: 'column_2', title: 'Column 2', type: 'text'}
,{ name: 'column_3', title: 'Column 3', type: 'text'}
];
$('#my-table').jsGrid({
width: '100%',
height:'700px',
filtering:true,
editing: false,
paging: true,
autoload: false,
sorting: true,
pageLoading: true,
pageSize: 20,
controller: jsGridController,
fields: TABLE_COLUMNS,
rowClick: function(args){
},
onDataLoading: function(args){
},
onDataLoaded: function(args){
}
});
Is this a timing thing, ES Module thing, or a jsGrid library thing? Cannot figure it out. I have also tried setting it to when the document is ready and also a delay of a few seconds and neither works.