1

Report detalization

Тема: Report detalization

Hi,
when i execute report whit SDK playgroung execute_report, like this:

function executeReport(){ // execute selected report
    // get data from corresponding fields
    var id_res=$("#res").val(), id_templ=$("#templ").val(), id_unit=$("#units").val(), time=$("#interval").val();
    if(!id_res){ msg("Select resource"); return;} // exit if no resource selected
    if(!id_templ){ msg("Select report template"); return;} // exit if no report template selected
    if(!id_unit){ msg("Select unit"); return;} // exit if no unit selected

    var sess = wialon.core.Session.getInstance(); // get instance of current Session
    var res = sess.getItem(id_res); // get resource by id
    var to = sess.getServerTime(); // get current server time (end time of report time interval)
    var from = to - parseInt( $("#interval").val(), 10); // calculate start time of report
    // specify time interval object
    var interval = { "from": from, "to": to, "flags": wialon.item.MReport.intervalFlag.absolute };
    var template = res.getReport(id_templ); // get report template by id
    $("#exec_btn").prop("disabled", true); // disable button (to prevent multiclick while execute)

    res.execReport(template, id_unit, 0, interval, // execute selected report
        function(code, data) { // execReport template
            $("#exec_btn").prop("disabled", false); // enable button
            if(code){ msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code
            if(!data.getTables().length){ // exit if no tables obtained
                msg("<b>There is no data generated</b>"); return; }
            else showReportResult(data); // show report result
    });
}

function showReportResult(result){ // show result after report execute
    var tables = result.getTables(); // get report tables
    if (!tables) return; // exit if no tables
    for(var i=0; i < tables.length; i++){ // cycle on tables
        // html contains information about one table
        var html = "<b>"+ tables[i].label +"</b><div class='wrap'><table style='width:100%'>";
        
        var headers = tables[i].header; // get table headers
        html += "<tr>"; // open header row
        for (var j=0; j<headers.length; j++) // add header
            html += "<th>" + headers[j] + "</th>";
        html += "</tr>"; // close header row
        result.getTableRows(i, 0, tables[i].rows, // get Table rows
            qx.lang.Function.bind( function(html, code, rows) { // getTableRows callback
                if (code) {msg(wialon.core.Errors.getErrorText(code)); return;} // exit if error code
                for(var j in rows) { // cycle on table rows
                    if (typeof rows[j].c == "undefined") continue; // skip empty rows
                    html += "<tr"+(j%2==1?" class='odd' ":"")+">"; // open table row
                    for (var k = 0; k < rows[j].c.length; k++) // add ceils to table
                        html += "<td>" + getTableValue(rows[j].c[k]) + "</td>";
                    html += "</tr>";// close table row
                }
                html += "</table>";
                msg(html +"</div>");
            }, this, html)
        );
    }
}

function getTableValue(data) { // calculate ceil value
    if (typeof data == "object")
        if (typeof data.t == "string") return data.t; else return "";
    else return data;
}

it isn't gives me report's detalization.
How can i get it?
thank you

2

Report detalization

Re: Report detalization

janus, try this function:

result.getRowDetail(tableIndex, rowIndex, callback);
Head of Wialon Local Department
Gurtam