Author Topic: how to change(or update) colModel....  (Read 2555 times)

petitelin

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 5
    • View Profile
how to change(or update) colModel....
« on: November 13, 2020, 03:18:55 pm »
hi~


after loaded, i got the json data with dataModel.url..
i want to add more Column with this json data key..



      var grid;
        $(function () {
            colM = new Array();
            colM.push({title: "all", align: "center", dataIndx : 'sAll', type:'checkbox', dataType: 'bool', cb: {all: true, header: false},editable: true});
            colM.push({title: "subject", align: "center", dataIndx: "subject"});
            colM.push({title: "help", align: "center", dataIndx: "help"});
            colM.push({title: "id", align: "center", dataIndx: "id"});

            pqGridObj.colModel = colM;
            pqGridObj.pageModel.type = null;
            pqGridObj.height = nowHeight();
            pqGridObj.toolbar = null;
            pqGridObj.dataModel.url = "auth_ori.run";
            pqGridObj.dataModel.recIndx = "id";
            pqGridObj.dataModel.getData = function (response) {
                if (response.data.length>0){
                    var dataObj = Object.getOwnPropertyNames(response.data[0]);

                    for(i=0;i<dataObj.length;i++) {
                        if(dataObj.indexOf("admin_")>=0) {
                           colM.push({dataIndx: dataObj, title: dataObj.split("_")[2], type: 'checkbox', dataType: 'bool', cb: {header: true, all: true}, editable: true});
>>>>>>>>>>>>>>> column read data.......but, did not create checkbox, title, and title_checkbox.....

                        }
                    }
                }
                grid.colModel = colM;
                return { data: response.data };

            };
            grid = pq.grid("#grid_json_scroll",pqGridObj);
        })

« Last Edit: November 13, 2020, 03:20:49 pm by petitelin »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: how to change(or update) colModel....
« Reply #1 on: November 15, 2020, 10:19:58 am »
It would be

Code: [Select]
grid.refreshCM( colM );

instead of

Code: [Select]
grid.colModel = colM; //this is wrong.

Columns API can be also be used to add columns dynamically:

https://paramquery.com/pro/api#method-Columns