index column prints [object Object ]

index column prints [object Object ]

mickeyjsmickeyjs Posts: 9Questions: 3Answers: 0
edited July 2017 in Free community support

Hello Team,
when i click on Print button it shows [object object ] inside index column

debug file url : http://debug.datatables.net/okagug
index column : function : t.on('order.dt search.dt', function () {
t.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
t.cell(cell).invalidate('dom');
});
}).draw();

what causing this ??
Please help !!!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    I was going to say that you need to use cell().invalidate(), but I see you are already using that. As such I would need a test case showing the issue to be able to help debug the issue.

    Thanks,
    Allan

  • mickeyjsmickeyjs Posts: 9Questions: 3Answers: 0

    Thanks for the Quick response Allan !!
    As suggested test case url : http://live.datatables.net/woboviqi/1/edit

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin
    Answer ✓

    Super - thanks!

    Its being caused by:

    data: null

    for the first column. That tells DataTables that it should use the original object for the row as the data source for the column. That's only useful when combined with columns.render.

    Instead, in this case what I think you should do is set columns.data to be a property that doesn't exist in the object (then DataTables will write to it when cell().invalidate() is called) and use columns.defaultContent to stop any error messages appearing:

    { 'data': 'id', defaultContent: '' },
    

    Updated example: http://live.datatables.net/woboviqi/2/edit

    Allan

  • mickeyjsmickeyjs Posts: 9Questions: 3Answers: 0
    edited July 2017

    Thanks you very much allan . it works great !!!

    one more question as my json does not contain any id column , how datatables process this line of code
    { 'data': 'id', defaultContent: '' },

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    It will attempt to read a property called id. When it finds that there isn't such a property it will just use the defaultContent (empty string in this case).

    When you call cell().invalidate() it will actually write the value into a new id property.

    Allan

This discussion has been closed.