getting string out of row().data( )

getting string out of row().data( )

andychuandychu Posts: 2Questions: 1Answers: 0

Hi guys,

Instead of clicking cell one by one with cell().data
Is there a way to get the list of string out of row().data ?

I read from that forum that the Row() is Object Data.
And when I try to
$('#example1 tbody').on( 'click', 'td', function () {
var allrow = table.row(this).data();
alert( allrow );
} );

The alert show the row that I clicked like thisRowCell1,thisRowCell2,hellworld
all separated with ","

I tried to split the text using "," and I still fail.
I do not want to go all the way using ID, Ajax to handle this. (because I'm very new to programming)

I simply, just want to be able to click certain row and that
thisRowCell1 is pasted in other target (#id)
while thisRowCell2 show in another target. (#id)

Thank you in advance ! =)

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited February 2020

    table.row(this).data()

    This will return object based data if you are using columns.data. Based on your description you are not using columns.data since its returning an array.

    I tried to split the text using "," and I still fail.

    You don't need to do this since its already an array.

    I simply, just want to be able to click certain row and that
    thisRowCell1 is pasted in other target (#id)
    while thisRowCell2 show in another target. (#id)

    Since the allrow is an array you would access the first element with var thisRowCell1 = allrow[0].

    Kevin

  • andychuandychu Posts: 2Questions: 1Answers: 0

    oh Kevin, you save my daysssss.
    Thank you so much for clear explanation and examples.

    I tried something like alert(allowrow[0]); before but it didn't work
    little that I know, I have to var thisRowCell1 = allrow[0] and then alert(thisRowCell1);
    now everything works just fine. I love it so much !!

    Thank you so so so much.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hmm - that doesn't sound right. alert(allrow[0]) is exactly the same as var thisRowCell1 = allrow[0]; alert(thisRowCell1);.

    I'd need to see an example of both causing the different behaviour to be able to explain that though.

    Allan

This discussion has been closed.