开发者

How to change a specific RowData value in a jqGrid?

开发者 https://www.devze.com 2022-12-16 12:09 出处:网络
And the script used is <script type=\"text/javascript\"> var lastSelection; var idCategoria; var n开发者_Go百科omeCategoria;

And the script used is

<script type="text/javascript">

        var lastSelection;
        var idCategoria;
        var n开发者_Go百科omeCategoria;

        function editRow(id) {
            if (id && id !== lastSelection) {
                var grid = jQuery("#<%= JQGrid1.ClientID %>");

                if (document.getElementById(lastSelection + "_NomeCategoria") != null) {
                    if ( document.getElementById(lastSelection + "_NomeCategoria").value != undefined ) {
                        var objeto = document.getElementById(lastSelection + "_NomeCategoria");
                        idCategoria = objeto.value;
                        nomeCategoria = objeto[objeto.selectedIndex].text;
                    }
                }

                if (lastSelection != undefined) {
                    grid.updateGridRows("{IdCategoria:" + idCategoria + "}", lastSelection);
                    grid.saveRow(lastSelection, false);
                    //grid.setCell(lastSelection, "IdCategoria", idCategoria);
                    //grid.setRowData(lastSelection, "{IdCategoria:" + idCategoria + "}");
                }

                try
                {
                    grid.restoreRow(lastSelection, defineCategoria);
                }
                catch(err)
                {
                    alert(err.description);
                }
                grid.editRow(id, true, selecionaCategoria);
                lastSelection = id;
            }
        }

        function selecionaCategoria(id) {

            var grid = jQuery("#<%= JQGrid1.ClientID %>");
            var linha = grid.getRowData(id);
            var idCategoria = linha.IdCategoria;
            var comboCategorias = document.getElementById(id + "_NomeCategoria");
            if (idCategoria != "" && idCategoria != undefined) {
                try {
                    for (var i = 0; i < comboCategorias.childNodes.length; i++) {
                        if (comboCategorias.childNodes[i].value == idCategoria) {
                            comboCategorias.childNodes[i].selected = true;
                            break;
                        }
                    }
                }
                catch (err) {
                    alert(err.description);
                }
            }
        }

        function defineCategoria(id) {
            var grid = jQuery("#<%= JQGrid1.ClientID %>");
            grid.setCell(id, "NomeCategoria", DefineUrlCategoria(idCategoria, nomeCategoria));
        }

        // The FormatFunction for CustomFormatter gets three parameters
        // cellValue - the original value of the cell
        // options - as set of options, e.g
        //   options.rowId - the primary key of the row
        //   options.colModel - colModel of the column
        // rowData - array of cell data for the row, so you can access other cells in the row if needed

        function DefineUrl(cellValue, options, rowObject) {
            var caminho = "";
            if (isArray(rowObject)) {
                if (rowObject[1] != "" && rowObject[1] != undefined) {
                    //var caminho = "<a href='/Ferramenta/Graficos/GraficoCategoria.aspx?idCategoria=" + rowObject[1] + "'>" + cellValue + "</a>";
                    caminho = DefineUrlCategoria(rowObject[1], cellValue);
                }
                else {
                    caminho = cellValue;
                }
            }
            else {
                if (idCategoria != "0") {
                    caminho = DefineUrlCategoria(idCategoria, nomeCategoria);
                }
                else {
                    caminho = nomeCategoria;
                }
            }
            return caminho;
        }

        function isArray(o) {
            return (typeof (o.length) == "undefined") ? false : true;
        }


        function DefineUrlCategoria(idCategoria, nomeCategoria) {
            var caminho = "<a href='/Ferramenta/Graficos/GraficoCategoria.aspx?idCategoria=" + idCategoria + "'>" + nomeCategoria + "</a>";

            return caminho;
        }
    </script>

When the rows are not in edit mode the fifth columns shows a link and while editing it shows a dropdown. To select the correct item in the dropdown I use the second column that has the ID that came from the database.

The problem is that after changing the item and saving it to the database, this column value doesn't change. How can I do it after the grid.saveRow(lastSelection, false); ?

Thanks.


I have found the solution !

I changed the code below

if (lastSelection != undefined) {
    grid.updateGridRows("{IdCategoria:" + idCategoria + "}", lastSelection);
    grid.saveRow(lastSelection, false);
    //grid.setCell(lastSelection, "IdCategoria", idCategoria);
    //grid.setRowData(lastSelection, "{IdCategoria:" + idCategoria + "}");

}

To this

if (lastSelection != undefined) {
    grid.setRowData(lastSelection, {IdCategoria:idCategoria});
    grid.saveRow(lastSelection, false);}

The problem was that I was passing the second parameter as a string.

0

精彩评论

暂无评论...
验证码 换一张
取 消