Как динамически добавлять столбцы в slickgrid?

Santosh Kumar спросил: 11 марта 2019 в 07:24 в: javascript

Я пытаюсь добавить динамические столбцы в slickgrid, просматривая объект массива javascript.

Формат объекта в массиве js:

 auditor = {"firstName":"test audit manager","lastName":".","middleName":null,"partyId":"11140"}var columns = [];
/*from the ajax result, I'm obtaining 'auditors' js array */for (var key in auditors) {var auditor =  auditors[key];
                    var name = auditor["firstName"];                    if(auditor["middleName"]){
                        name += auditor["middleName"];
                    }
                    if(auditor["lastName"]){
                        name += auditor["lastName"];
                    }
                    if(auditors[parseInt(key)+parseInt(1)]){
                        columns = columns += '{id: '+'"auditor_'+key+'", name: '+'"'+name+'"'+', field: '+'"auditor_'+key+'", editor: Slick.Editors.Text, width:80, minWidth:80, sortable:true, focusable:false},'; 
                    }
                    else{
                        columns = columns += '{id: '+'"auditor_'+key+'", name: '+'"'+name+'"'+', field: '+'"auditor_'+key+'", editor: Slick.Editors.Text, width:80, minWidth:80, sortable:true, focusable:false}';
                    }
                }//end for loopcolumns.replace(/\\\//g, "/");var options = {
                enableCellNavigation: true,
                enableColumnReorder: false,
                editable: true,       
                forceFitColumns: false,         
                enableCellNavigation: true,
                //enableAddRow: true,
                asyncEditorLoading: false,          
                autoEdit: true,
                secondaryHeaderRowHeight: 25
            };            $(function () {
                grid = new Slick.Grid("#myGrid", data, columns, options);
                grid.setSelectionModel(new Slick.CellSelectionModel()); 
                var columnpicker = new Slick.Controls.ColumnPicker(columns, grid, options);                grid.onAddNewRow.subscribe(function (e, args) {
                    var item = args.item;   
                    grid.invalidateRow(data.length);
                    data.push(item);
                    grid.updateRowCount();
                    grid.render();
                });
            });

0 ответов