EasyUI Forum
April 28, 2024, 04:33:35 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datagrid - Dynamic column  (Read 2952 times)
firob
Newbie
*
Posts: 2


View Profile Email
« on: April 01, 2020, 08:00:46 PM »

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.png
I 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 :

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 :
Code:
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 :
Code:
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
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: April 01, 2020, 11:21:37 PM »

Please try this code instead.
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
    });
});
Logged
firob
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: April 01, 2020, 11:35:25 PM »

Oh !! It's working now ! Wow thank you so much, I just spent hours trying to figure this out.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!