Column names from string array

Column names from string array

ebagaipoebagaipo Posts: 13Questions: 5Answers: 0

How to populate datatables' column names from string array, ex. ["Payee Id","Payee Name","Payee Email"]?

Many thanks

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,215Questions: 1Answers: 2,592
    Answer ✓

    Hi @ebagaipo ,

    You can just iterate over that array and create the initialisation object for DataTables. The option you want is either columns.name or columns.title.

    Cheers,

    Colin

  • ebagaipoebagaipo Posts: 13Questions: 5Answers: 0

    Hi Colin,

    Thank you for the hint.

    This works for me:

            var columnNames = columnDescriptions.split(',');
            var mDataArray = new Array();
            var keys = Object.keys(columnNames);
            for (var i = 0; i < keys.length; i++) {
                var temp = new Object();
                if (columnNames[i].toString().length > 0) {
                    temp["sTitle"] = columnNames[i].toString();
                    mDataArray.push(temp);
                }
            }
    
This discussion has been closed.