How to assign a string with angle brackets to a cell in Tabulator.js, for example: "a<b<c"?
P粉718730956
P粉718730956 2023-08-03 13:48:37
0
1
550
<p>I have a cell in a Tabulator table that uses a list type editor. The options are populated by an array of strings that look like this (for example): </p> <pre class="brush:php;toolbar:false;">[ "a<b", "b<c", "c<d", ]</pre> <p>When the list editor is populated (using editorParams:{values:exampleOptions} in the column definition), or when I use setValue() directly on the cell, it discards what follows the angle brackets. So in the dropdown I see something like this: </p> <pre class="brush:php;toolbar:false;">"a", "b", "c",</pre> <p>How to display complete string in dropdown list/cell? </p>
P粉718730956
P粉718730956

reply all(1)
P粉659378577

One way is to use the itemFormatter option in editorParams to define a new element node for the list of values ​​and return the innerHTML of the element containing the list value:

editorParams: {
  values: ["a<b", "b<c", "c<d"],
  itemFormatter: (label, value, item, element) => {
    const listNode = document.createTextNode(value);
    element.appendChild(listNode);

    return element.innerHTML;
  }
},

This is an example on the name column:


const data = [{
    id: 1,
    name: 'Billy Bob',
    age: '12',
    gender: 'male',
    height: 1,
    col: 'red',
    dob: '',
    cheese: 1
  },
  {
    id: 2,
    name: 'Mary May',
    age: '1',
    gender: 'female',
    height: 2,
    col: 'blue',
    dob: '14/05/1982',
    cheese: true
  },
  {
    id: 10,
    name: 'Margret Marmajuke',
    age: '16',
    gender: 'female',
    height: 5,
    col: 'yellow',
    dob: '31/01/1999'
  }
]

const table = new Tabulator('#example-table', {
  data: data,
  columns: [{
      title: 'Name',
      field: 'name',
      editor: "list",
      editorParams: {
        values: ["a<b", "b<c", "c<d"],
        itemFormatter: (label, value, item, element) => {
          const listNode = document.createTextNode(value);
          element.appendChild(listNode);

          return element.innerHTML;
        }
      },
    },
    {
      title: 'Age',
      field: 'age'
    },
    {
      title: 'Gender',
      field: 'gender'
    },
    {
      title: 'Height',
      field: 'height'
    },
    {
      title: 'Favourite Color',
      field: 'col'
    }
  ]
})
<link href="https://unpkg.com/tabulator-tables@5.5.1/dist/css/tabulator.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.5.1/dist/js/tabulator.min.js"></script>
<div id="example-table"></div>


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!