Columns names cannot call in array form??

Columns names cannot call in array form??

eoam13eoam13 Posts: 2Questions: 1Answers: 0

Hi everyone. I have the following:

$(document).ready(function() {
    $('#example').DataTable( {
        data: arrObj,
        columns: arrObj2,
     } );
} );

arrObj2 is an array but it is not working. It does not show the titles for each column. How can I change this?

BR

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    It's most likely related to your arrObj2 not being in valid format. Can provide that?

  • allanallan Posts: 63,783Questions: 1Answers: 10,511 Site admin

    Agreed - we'd to know the contents of arrObj and arrObj2.

    Allan

  • eoam13eoam13 Posts: 2Questions: 1Answers: 0

    I am sorry for the late response. arrObj2 is coming from:

    rs.MoveFirst();
    var trr = 0;
    var trr = rs.Fields.Count
    rs.MoveFirst();
    var arrObj = [];
    var arrObjN = [];
    while (rs.EOF != true){
    var arrObj1 = [];
    var arrObj2 = [];
    var str = [];
    var i = 0;
    
    while (i < trr) {
        str = [rs.Fields(i).value];
        str1 = [rs.Fields(i).Name];
        arrObj1.push(str);
        arrObj2.push(str1);
        i++;
    }
    arrObj.push(arrObj1);
    arrObjN.push(arrObj2);
    rs.MoveNext();
    
    

    Thanks.

  • allanallan Posts: 63,783Questions: 1Answers: 10,511 Site admin

    If I'm reading the code above correctly you are just setting columns to an array of strings. Is that correct? Is so, that's not a validate DataTables initialisation. See columns and columns.title for how to set a column title.

    Allan

This discussion has been closed.