Empty Slick Grid with add/remove row and a "Return All Data From The SlickGrid Function"

已查看 962 次
跳至第一个未读帖子

Leonardo Resende Correa Lima

未读,
2016年6月2日 13:11:442016/6/2
收件人 SlickGrid
I have this code that creates an empty Slick Grid with the possibility to add new rows onAddNewRow and to delete the row by clicking in the last cell onClick.Subscribe

I have 3 questions:
  1. Is there a method to save the grid data using the api, for example returning a JSON?
  2. Is there a method to, for example, when a save button is clicked, to remove the class "editable"from the cell and save the value in the cell, so later I can get this values an transforming in a JSON ?
  3. Is there a way to validate the type of value inserted in the cell, like string or only integer?
        var grid;
        var data = [];
        var columns = [
          { id: "quantidade", name: "Quantidade", field: "Quantidade", width: 30, editor: Slick.Editors.Text },
          { id: "dimensao", name: "Dimensão", field: "Dimensao", width: 30, editor: Slick.Editors.Text },
          { id: "peso", name: "Peso", field: "Peso", width: 30, editor: Slick.Editors.Text },
          { id: "acao", name: "Ação", field: "Acao", width: 30, formatter: botaoRemoverFormatter, cssClass: "slick-align-center" },
        ];

        var options = {
            editable: true,
            enableAddRow: true,
            enableCellNavigation: true,
            enableColumnReorder: false,
            asyncEditorLoading: false,
        };

        grid = new Slick.Grid("#GridDetalhesCargaNovaRT", data, columns, options);
        grid.autosizeColumns();

        grid.onAddNewRow.subscribe(function (e, args) {
            var item = args.item;
            var column = args.column;
            grid.invalidateRow(data.length);
            data.push(item);
            grid.updateRowCount();
            grid.autosizeColumns();
            grid.render();
        });
        grid.onClick.subscribe(function (e, args) {
            if (args.cell == "3") {
                var linhaAtual = args.row;
                if (confirm("Deseja excluir esta linha?")) {
                    var gridData = grid.getData();
                    gridData.splice(linhaAtual, 1);

                    while (linhaAtual < gridData.length) {
                        grid.invalidateRow(linhaAtual);
                        linhaAtual++;
                    }
                    grid.updateRowCount();
                    grid.autosizeColumns()
                    grid.render();
                }
            }
        });


回复全部
回复作者
转发
0 个新帖子