How to add unique attribute in TR?
How to add unique attribute in TR?
shahen
Posts: 18Questions: 2Answers: 0
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
This discussion has been closed.
Answers
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
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?
I'm not getting it in that case I'm afraid. The code above will write the values from
subId
to thesubId
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 sincesubId
doesn't appear to change between rows.Allan
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];
How do you know what row index each entry in the subId array refers to?
Allan
Dy turns. subId[0] is for row1, subId[1] is for row2 ....
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].
By turns
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.
Yes, I would suggest that if you can, include the row id in the original data source.
Allan
I am trying. Thank You