Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

IBM Cognos Analytics with jQuery/DataTables drawn or setData function problem

  • 1.  IBM Cognos Analytics with jQuery/DataTables drawn or setData function problem

    Posted Fri March 22, 2019 07:06 AM
    The following JavaScript works fine if I pass t_dataSet into DataTable but does not work (e.g no data) if I instead pass this.dataSet.

    define( ['jquery', 'https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js'], function($, Datatables) {
    "use strict";
    
    function DatatablesSimpleList() {}
    
    DatatablesSimpleList.prototype.draw = function( oControlHost ) {
    
        let htmlElement = oControlHost.container;
        htmlElement.innerHTML = '<table id="datatable_example" class="display" width="100%"></table>';
    
        var t_dataSet = [
            [ "Tiger Nixon" ],
            [ "Garrett Winters"],
            [ "Ashton Cox"]
        ];
    
        $(function () {
            $('#datatable_example').DataTable({
                data: t_dataSet,        // this works
                //data: this.dataSet,   // this does not work
                columns: [{ title: "Name" }]
            });
    
        });
    };
    
    DatatablesSimpleList.prototype.setData = function( oControlHost, oDataStore ) {
    
        this.dataSet = [
            [ "Tiger Nixon" ],
            [ "Garrett Winters"],
            [ "Ashton Cox"]
        ];
    };
    
    return DatatablesSimpleList;});


    Any ideas on why this is not working as expected?



    ------------------------------
    Patrick Garner
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: IBM Cognos Analytics with jQuery/DataTables drawn or setData function problem

    Posted Wed April 10, 2019 10:25 AM
    Hi,

    i'm also new to custom controls, but i think i've figured out while yours isnt't working:

    In the Cognos Report you have to add a data set to your custom control.
    - click on the "(+)"-Symbol
    - add a query calculation to the categories (e.g. Name: dummy; Expression 1)

    additionally alter your code:
        var m_dataSet = this.dataSet;
    	
        $(function () {
            $('#datatable_example').DataTable( {
                data: m_dataSet,   // this does not work
                columns: [{ title: "Name" }]
            });
    
        });






    ------------------------------
    bj ml
    ------------------------------