Creating matrix from matrix datasource

Posted by: baloghbencefacebook on 12 April 2021, 5:14 pm EST

    • Post Options:
    • Link

    Posted 12 April 2021, 5:14 pm EST

    I have a matrix datasource which I would like to use to create a matrix with spreadjs, but so far I could not find a way to pass the matrix or create its columns and rows in order to form a multi-level matrix

  • Posted 13 April 2021, 10:50 pm EST

    Hi,

    You may set/get the 2D array of data with the getArray/setArray method. Please refer to the following code snippet and let us know if you face any issues.

    
    //set value
    var array = [[1,2,3],[4,5],[6,7,8,9]];
    activeSheet.setArray(1, 2, array);
    //set formula
    var array = [["=1+1","=2+2","=3+3"],["=4+4","=5+5"],["=6+6","=7+7","=8+8","=9+9"]];
    activeSheet.setArray(1, 2, array, true);
    //get value
    var newArray = activeSheet.getArray(1, 2, 3, 4);
    //getformula
    var newArray = activeSheet.getArray(1, 2, 3, 4, true);
    //alert(newArray[0]);
    
    

    API References:

    setArray: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Worksheet~setArray.html

    getArray: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Worksheet~getArray.html

    Regards

    Avinash

  • Posted 15 April 2021, 7:27 pm EST

    this doesn’t seem to be a usable way to pass a matrix, since you do not know which headers does a value belongs to

  • Posted 15 April 2021, 11:34 pm EST

    Hi,

    For this you need to create the JSON object from the matrix and then use the set datasource method for binding the datasource and columns on the sheet. Please refer to the following code snippet and attached sample that demonstrate the same.

    
       var customers = [
           { ID:0, Name:'A', Info1:'Info0' },
           { ID:1, Name:'B', Info1:'Info1' },
           { ID:2, Name:'C', Info1:'Info2' },
        ];
        sheet.autoGenerateColumns = true;
        sheet.setDataSource(customers);
    
    

    setDataSource Demo: https://www.grapecity.com/spreadjs/demos/features/data-binding/sheet-level-binding#demo_source_name

    Regards

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels