JavaScript does not accept variable value

1

I'm trying to do a function to call a GRID that will be different depending on the parameter I pass. This is the function:

$JQuery(document).ready(function() {
    $.ajax({
        url: "/main/conciliacao/gera-colunas/tabela/<?php echo $tabela ?>",
        success: function(data, st) {
            criaGrid(data);
        },
        error: function() {
            alert("Erro ao retornar os valores das colunas");
        }
    });
});

function criaGrid(colM) {
    $JQuery("#jqGrid").jqGrid({
        url: "/main/conciliacao/gera-grid/processo/<?php echo $processo ?>/tabela/<?php echo $tabela ?>/id/<?php echo $id ?>",
        datatype: "json",
        colModel: [ colM ],
        viewrecords: true, 
        width: 780,
        height: 200,
        rowNum: 30,
        pager: "#jqGridPager"
    });
}

My problem is that the variable colM has what I need to create the grid columns, but if I call it in colModel: the function does not recognize the value of the variable.

What could be happening?

    
asked by anonymous 30.01.2015 / 14:59

1 answer

2

If you look at the plugin documentation , you will see that colModel does not expect an array as you are passing, but an object. You can pass colM directly, without wrapping an array:

function criaGrid(colM) {
    $JQuery("#jqGrid").jqGrid({
        url: "/main/conciliacao/gera-grid/processo/<?php echo $processo ?>/tabela/<?php echo $tabela ?>/id/<?php echo $id ?>",
        datatype: "json",
        colModel: colM,
        viewrecords: true, 
        width: 780,
        height: 200,
        rowNum: 30,
        pager: "#jqGridPager"
    });
}

But this table property you have in your colM is not one of the options valid for colModel , I'm not sure what your intent is with this value.

As for your comment that passing the variable it does not accept, it may be because your JSON is not being interpreted as such. To resolve this, please report in the ajax call that the return will be a JSON:

$.ajax({
    url: "/main/conciliacao/gera-colunas/tabela/<?php echo $tabela ?>",
    dataType: "json", // <--- aqui
    success: function(data, st) {
        criaGrid(data);
    },
    error: function() {
        alert("Erro ao retornar os valores das colunas");
    }
});
    
30.01.2015 / 15:19