1

I'm using jQuery DataTables for one project. I applied datatable to an existing table, as shown below:

var table = '#datatable-1';
var dataTable = $(table).DataTable({
    'paging'      : true,
    'lengthChange': true,
    'searching'   : true,
    'ordering'    : true,
    'info'        : true,
    'autoWidth'   : false,
    select: {
        style: 'multi'
    }
});

Then I iterate over each row of the table, try to get the row content, but I obtained some HTML inside.

dataTable.rows({
    order: 'applied',
    page: 'all',
    search: 'applied',
    selected: true
}).every(function (rowIdx, tableLoop, rowLoop) {
    console.log(this.data());
});

This is my like my table sees

And this is the result after I do a console.log(this.data()).

Array [ "A &amp; B", "143 AVE", "", "AMAZON", "EU", "", "<textarea name="" rows="1"></textar…" ]

Anyone knows how to get the row content like is shown in the table?

0

2 Answers 2

1

You can iterate over dummy elements to translate html entities by text() or extract form input values by val() (as I believe you want as well) :

table.rows().every(function() {
  var data = this.data();
  data.forEach(function(d, index, arr) {
    d = $('<div>').html(d);
    arr[index] = d.val() || d.text()
  })
  console.log(data)
})

demo -> http://jsfiddle.net/ocL7xhzg/

In your case the array would be logged out as

Array [ "A & B", "143 AVE", "", "AMAZON", "EU", "", "" ]
Sign up to request clarification or add additional context in comments.

3 Comments

Fix the issue parcial, if you change the text of textarea the new value is not recognize and not show.
@omixam, ??, this is how DataTables works. has nothing to do with your question. If you want DataTables internal cache to be updated with changes in form input see this answer -> stackoverflow.com/a/27860934/1407478 it is easy to overcome -> jsfiddle.net/ocL7xhzg/1
you have reason, this is like datatables works. Thanks for the bonus.
0

You have an Array. You can get first record (A & B) with this.data()[0]. Increase array index for next values.

1 Comment

How you can see above, if I do that I will obtain "A &amp; B" and not "A & B" that is the current value for this position. Also, there is textarea tag shows in the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.