How to add unique attribute in TR?

How to add unique attribute in TR?

shahenshahen Posts: 18Questions: 2Answers: 0
edited January 2018 in Free community support

I have a form. After submission the data is sent to database. I want to show all submissions details in dashboard with dataTables.js, What how it looks like.

table = $('#entries').DataTable({
        lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        data: data_table,
        aoColumnDefs: [{ aTargets: -1, bSortable: false, bSearchable: false}],
        "aaSorting": [[0,'desc']],
        columns: Submissions.data_columns,
        createdRow:function(row,data,dataIndex){
            console.log(subId);
            for(i=0; i<subId.length; i++){ 
                $(row).attr("subId",subId[i]);
            }   
        }
});

subId is an array where i have submissions' Ids of the form. Is there a way that I could use to add subId's to each row?

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin

    Is the id in the data? If so use row.id = data[0]; (or wherever the id value that you want to assign is).

    Allan

  • shahenshahen Posts: 18Questions: 2Answers: 0

    No. The ids are only in array subId. And i have to give the custom id to each row. and these id's are different numbers not 0,1,2,3,..... is it posible?

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin

    I'm not getting it in that case I'm afraid. The code above will write the values from subId to the subId attribute for every row. If there is more then one value in the array it will overwrite the previous value since an attribute can only have a single value. Likewise, all rows will have the same values since subId doesn't appear to change between rows.

    Allan

  • shahenshahen Posts: 18Questions: 2Answers: 0

    You are right. That is my problem))))
    Suppose var subId = [1348,45487,454,13164,654,99]; I want to something like this.
    row1.attr["subId"] =subId[0];
    row2.attr["subId"] =subId[1];
    row3.attr["subId"] =subId[2];
    row4.attr["subId"] =subId[3];
    row5.attr["subId"] =subId[4];
    row6.attr["subId"] =subId[5];

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin

    How do you know what row index each entry in the subId array refers to?

    Allan

  • shahenshahen Posts: 18Questions: 2Answers: 0

    Dy turns. subId[0] is for row1, subId[1] is for row2 ....

  • shahenshahen Posts: 18Questions: 2Answers: 0

    subId I get from base. I solved this task. every time when clicking the row I get this.rowIndex. and then I take subId[this.rowIndex-1].

  • shahenshahen Posts: 18Questions: 2Answers: 0

    By turns

  • shahenshahen Posts: 18Questions: 2Answers: 0

    Allan You are right. When sorting the rows the rowIndex is being changed. And Now I need to give rowId. But maybe I am wrong anywhere.

  • allanallan Posts: 62,338Questions: 1Answers: 10,228 Site admin
    Answer ✓

    Yes, I would suggest that if you can, include the row id in the original data source.

    Allan

  • shahenshahen Posts: 18Questions: 2Answers: 0

    I am trying. Thank You

This discussion has been closed.