How to ignore first <tr> in jquery.datatables?

Asked

Viewed 155 times

0

I have a table where the first <tr> I put an image, if when I search comes along the name of the image.

For example: in the first row of table a img is named after head.png and the rest of the line doesn’t have the letter p.

Only when I put to search "p" the search shows me the first line.

But when I put at least one line without img he can search.

  • There must be something wrong with your code, because the search only looks for text and ignores tags and what’s inside them.

  • Because it’s more I don’t know where it is. when I search by head.png it searches everyone who has the image.

  • Then you’d have to show your code so we can try to reproduce the problem.

  • html or . js code?

  • Create a jsfiddle from post there html and js

1 answer

0

Update 24/12/2017

You can control what is searched (and even what is ordered) through the option Columns.render.

In this case, a function should be passed and treated when second parameter type have the content filter. The fourth parameter meta can help determine which is the line without depending on any additional data in the table, because meta.row is the index of the line.

It would look something like this:

render: function (data, type, row, meta) {
    if (type == "filter" && meta.row == 0)
        return "Texto customizado"; //aqui fica a seu critério o valor que será pesquisado

    return data;
}

Original response

You can control what is searched (and even what is ordered) through the option Columns.render.

In this case, a function should be passed and treated when second parameter type have the content filter. It would look something like this:

render: function (data, type) {
    if (type == "display")
        return data;
    else if (type == "filter")
        return "Texto customizado";
}
  • More in the case as I do to ignore the first <tr>? I still don’t understand.

  • For the first line, you can return undefined when the surrender guy is filter, so it is not included in the survey.

  • can edit the answer?

  • Updated response

  • As well as the value that will be searched?

  • You may have a specific value for research. I had a similar case in a project, where there was a column indicating whether the record was valid or invalid, but there was an image to indicate this. In this column, when the guy was display was returned the image html, when it was filter was returned "valid" or "invalid". So we were able to display one thing and search another.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.