Jessica Saxon
Jessica Saxon

Reputation: 91

How to use webix datamapping?

I'm using a webix datatable. I'm having trouble mapping my values for the table. The data isn't displaying, although I know it sees the data.

Here is my webix script with my mapping:

    webix.ajax().get('urltourltourl',{
        // Error callback
        error:function(text, data, XmlHttpRequest){
            alert("error");
        },

        //Success callback
        success:function(text, data, XmlHttpRequest){
            var data = JSON.parse(text);
            console.log(data);
        var dtable2 = webix.ui({
                container:"datatable",
                view:"datatable",
                map:{
                    1:data.data[0].centerNumber,
                    2:data.data[0].centerNumber
                },
                columns:[
                    { id:"1",   header:"CenterNBR" , width:88},
                    { id:"2",   header:"Loan NBR",  width:88},
                    { id:"3",   header:"Cust Name",     width:88},
                    { id:"4",   header:"MTD #",     width:88},
                    { id:"5",   header:"MTD $",     width:88},
                    { id:"6",   header:"MTD %",     width:88},
                    { id:"7",   header:"YTD #",     width:88},
                    { id:"8",   header:"YTD $",     width:88},
                    { id:"9",   header:"YTD %",     width:88},
                ],
                autoheight:true,
                autowidth:true,
                data: data
        }); 
        }
    });

The mapping should tie that ID with the value that I'm pulling from the data JSON object but it doesn't. It's just blank.

Upvotes: 0

Views: 209

Answers (1)

Aquatic
Aquatic

Reputation: 5144

If you want to use "map" attribute, you need to

  • change keys to alpha-numeric string ( not a numbers )
  • write the mapped values as strings

       map:{
         "a1":"#centerNumber#",
         "a2":"#centerNumber#" 
       },
       columns:[
            { id:"a1",   header:"CenterNBR" , width:88},
            { id:"a2",   header:"Loan NBR",  width:88},
    

http://webix.com/snippet/115c1e12

If you need to have the numeric keys, use scheme.init instead

      scheme:{
        $init:function(obj){
          obj[1] = obj.centerNumber;
          obj[1] = obj.centerNumber;
        }
      },

http://webix.com/snippet/2d1344bd

Upvotes: 1

Related Questions