1 Reply Latest reply: Jul 7, 2016 3:42 AM by Thibaut Schueller RSS

    how to make html table from data

    Christophe Brault

      Hi,

       

      My requirement is to extract data from a Sense app to pdf, for tables with lots of rows.

       

      Since it's not possible from the app, i think about doing it in a a mashup by doing a table from data, and then print the html page to pdf.

       

      But can't achieve to retrieve data from hypercube to hmtl...

       

      Does someone have an working example of how to do that kind off requirement ?

        • Re: how to make html table from data
          Thibaut Schueller

          Hello,

          An exemple how hypercubes works and how to create a table

          This function create a table

           

          function createCubebox( t ){  //t is the ID where I insert my table, here t = "#table" because I alread declare my table in //the html code, like <table id="table"></table>

          app.createCube({

            "qInitialDataFetch": [

            {

            "qHeight": 50, // Number of values who are load for each field

            "qWidth": 2    // Number of measures and dimensions

            }

            ],

            "qDimensions": [

            {

            "qDef": {

            "qFieldDefs": [

            "Item"     //First Dimension replace item by your first dimension field

            ]

            },

            "qNullSuppression": true

            }

            ],

            "qMeasures":[

          {

           

           

          "qDef": {

            "qFieldDefs": [

            "Item"   //First measure replace item by your first measure field

            ]

            },"qSortBy": {  

                        "qSortByState": 0,

                        "qSortByFrequency": 0,

                        "qSortByNumeric": -1,

                        "qSortByAscii": 0,

                        "qSortByLoadOrder": 0,

                        "qSortByExpression": 0,

                        "qExpression": {

                          "qv": ""

                        }},

           

           

          "qLibraryId": "ID" // if you generate your hypercube, he add this id for the field

          }]

            },function(u){

           

            $(t).empty(); //clear the section

            var e=u.qHyperCube,    //

            clo=document.createElement("thead"),

            o=document.createElement("tbody"),

            title1="first title",

            title2=e.qMeasureInfo[0].qFallbackTitle;  //get the name of the field for the second title

            $(clo).html("<tr><th>"+title1+"</th><th>"+title2+"</th></tr>").appendTo($(t));

            $.each(e.qDataPages[0].qMatrix,function()

            {

             var i=this[0], //the first value of the first field, here a dimension

             g=this[1], //the first value of the second field, here a measure

             f=document.createElement("tr"), //create the row

             d=document.createElement("td"), //create the first cell of the row

             d2=document.createElement("td"); //create the second cell of the row

             $(d).html(i.qText).appendTo($(f)).click(function(){app.field("/*Field_Name*/").selectValues([{qText:i.qText}],!0,!1);

            }); //add text to the first cell and append the cell to the row

             $(d2).html(g.qNum).appendTo($(f)); //add text to the second cell and append the cell to the row

             $(f).appendTo($(o));  //append the row to the tbody

            })

             $(o).appendTo($(t));

             }

            )};

           

            createCubebox("#table"); // call the function with the ID