0

As per Bootstrap Table documents, a data-field was created for TH but the data-field for TD is not in the document. Any idea about this?

$('#table').bootstrapTable({
url: 'data1.json',
pagination: true,
search: true,
columns: [{
  field: 'id',
  title: 'Item ID'
}, {
  field: 'name',
  title: 'Item Name'
}, {
  field: 'price',
  title: 'Item Price'
}]
})
isherwood
  • 58,414
  • 16
  • 114
  • 157
jsjq-finder
  • 165
  • 3
  • 15
  • I suspect that you mean _attribute_ and not tag. The [examples](https://examples.bootstrap-table.com/#welcomes/from-data.html) I checked don't show `data-field` attributes on data cells, just heading cells. The attribute would be the same for data cells anyway since they relate to the heading cell. Please revise to clarify your expectation and intended usage. – isherwood May 31 '23 at 19:40
  • @isherwood Needs to add a data-field attribute for TD as same as in TH, Because I need to addClass as per data-field attributes in TD. – jsjq-finder Jun 02 '23 at 03:45
  • 1
    You can add the data attributes yourself by [selecting the table column](https://stackoverflow.com/questions/8375625/how-to-select-a-table-column-with-jquery), or you can add the classes based on the attribute on the heading. – isherwood Jun 02 '23 at 12:40

1 Answers1

0

The data-field could really just be considered the column name, and that is why it applies to TH.

Is there a problem you're attempting to solve concerning data-field and TD? With more context I'm happy to edit/update this answer.

Or, am I misunderstanding your question and you mean the columns do not have the names specified in field?

Nick R
  • 76
  • 7
  • This seems more like a clarifying comment. Questions shouldn't be asked in answers. – isherwood May 31 '23 at 19:51
  • Yes, I agree, but I don't have enough rep to comment on the original question. However, I did think the first line was technically an answer, but given the question I thought there might be more to it and I could provide a better answer. – Nick R May 31 '23 at 20:12
  • Needs to add a data-field attribute for TD as same as in TH, Because I need to addClass as per data-field attributes in TD. – jsjq-finder Jun 02 '23 at 03:43
  • 1
    You could likely use a formatter instead if you need to add a class. ```columns: [{ field: 'id', title: 'Item ID', formatter: exampleformatter }, ``` and then make a function called exampleFormatter, in this case, that would return the value in a span with the class you want to add. It will automatically format all cells in that column. For very basic additions, you can also just define the column with `Item Name` for example – Nick R Jun 02 '23 at 05:29