Hi,
I'm trying to change dynamicly the columns of a datagrid with javascript. I get the following information from a php script that go in a database to get the information, then returning it to a json format with the information of the field, title and width. This code is in a function that is called when I change a parameter in a droplist, so the column adapt to that parameter.
The problem is, the header name of the column, or the width, doesn't work. Here a picture of what I see :
https://i.stack.imgur.com/58UEv.pngI see the column changing, when I change the parameter on the droplist menu, so that part is working. If I manually write the same parameters, it all works. But not when I try to generate it with my code.
So here the code :
var dg_grid = new Array();
var dg_column = new Array();
$.getJSON("lib/getDatagridInfo.php", function(result){
$.each(result, function(i, objet){
if(objet.visible == true){
var row = {
field: objet.dg_name,
title: objet.dg_label,
width: objet.dg_width
};
dg_grid.push(row);
}
});
});
console.log(dg_grid);
dg_column.push(dg_grid);
$('#dg').datagrid({
columns:dg_column
});
You can see on my picture the array that is generated in the console... If I do that same thing, but writing it myself :
var testrow = {field:"Dateheure",title:"Date",width:150};
And push that in my array, everything works fine.
I also noticed that if I try to compare that "testrow" that I write manually with my "row" that I generate with the code, with the same exact parameter list, using this :
console.log(row===testrow);
I get a false return, even if the array seems identical.
What am I doing wrong? How can I generate with javascript an array that will work to insert into the datagrid?
Thanks if you can help me