spring mvc - Problems about create dynamic columns with jgGrid -


i made demo create dynamic columns jqgrid table, faced problems. jqgrid code snippet:

$.ajax(     {         type: "get",         url: "reports/providerlist",         datatype: "json",         success: function(result)         {             var colnames = result.rows.colnames;             var colmodels = result.rows.colmodels;             $(grid_selector).jqgrid('gridunload');              jquery(grid_selector).jqgrid({                 url: 'reports/getdata',                 datatype: 'json',                 mtype: 'get',                 colnames: colnames,                 colmodel: colmodels,                 viewrecords : true,                 rownumbers:true,                 rownum:15,                 rowlist:[15,30],                 pager : pager_selector,                 altrows: true,                 loadcomplete : function() {                     var table = this;                     settimeout(function(){                         updatepagericons(table);                         enabletooltips(table);                     }, 0);                 },             });         },         error: function(x, e)         {             alert(x.readystate + " "+ x.status +" "+ e.msg);         }     }); 

my backend controller:

    @getmapping("/providerlist")     @responsebody     public map<string, object> providerlist(@requestparam(value = "rows", required = false) integer pagesize, @requestparam(value = "page", required = false) integer pagenumber){         jqgridmodel jqgridmodel = new jqgridmodel();         map<string, object> map = new hashedmap();         map.put("total", 4);         map.put("rows", jqgridmodel);         map.put("records", 6);         return map;     }      @getmapping("/getdata")     @responsebody     public map<string, object> getdata(){         list<coldata> coldatas = new arraylist<>();         coldata coldata1 = new coldata(2, "hello", new date().tostring(), "true", "admin");         coldata coldata2 = new coldata(5, "say", new date().tostring(), "false", "pechen");         coldatas.add(coldata1);         coldatas.add(coldata2);         coldatas.add(coldata2);          map<string, object> map = new hashedmap();         map.put("total", 4);         map.put("rows", coldatas);         map.put("records", 6);         return map;     } 

the data format @ backend:

public class jqgridmodel {     private list<string> colnames;     private list<colmodel> colmodels;      public jqgridmodel() {         colnames = new arraylist<>();         colnames.add("id");         colnames.add("name");         colnames.add("createtime");         colnames.add("status");         colnames.add("updateby");          colmodels = new arraylist<>();         colmodel colmodel1 = new colmodel("id", "id", 60f, false, false);         colmodel colmodel2 = new colmodel("name", "index", 60f, false, false);         colmodels.add(colmodel1);         colmodels.add(colmodel2);         colmodels.add(colmodel2);         colmodels.add(colmodel2);         colmodels.add(colmodel2);     } } 

but outcomes, no data shown in columns: enter image description here

i noticed /reports/providerlist , /reports/getdata hit in debug mode. what's going wrong, can help?

the origin of error seems me last lines of jqgridmodel constructor. use colmodels.add(colmodel2) multiple times. it's wrong. colnames contains labels: texts displayed in column headers. 1 allow use duplicates or empty strings in colnames. on other side colmodel have contains unique name values, can't empty, can't contains spaces.

you have change code of jqgridmodel constructor colmodels fill names, use fill colnames.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -