Kevin UI Kevin UI - 4 months ago 51
JSON Question

Bootstrap table, dashes in empty cells

When I load a bootstrap table with JSON, and the field is null like this:
"MyField": null

Bootstrap puts a dash or hyphen "-" in the empty table cell. What's the best way to turn this off/avoid this?

I am considering converting the nulls into empty strings, but I'd like to avoid that if possible.

Edit: example here https://jsfiddle.net/3k6qrswf/1/

<table id="table" class="table">
<thead>
<tr>
<th data-field="BookTitle">Title</th>
</tr>
</thead>
</table>

var testData = [
{"BookTitle": "abc"},
{"BookTitle": "def"},
{"BookTitle": null}
];

$('#table').bootstrapTable({
data: testData
});


Thanks

Answer

You can use undefinedText option to do what you want, documentation here.

$('#table').bootstrapTable({
    undefinedText: 'n/a',
    data: testData
});

Example: https://jsfiddle.net/3k6qrswf/2/.