Web page does not work when downloading Excel.
Web page does not work when downloading Excel.
I do not speak English, so please understand that I use a translator. My problem is as follows: If you click the Excel button after changing the head of the table to Select, the web page is stopped and it is in a standby state.
The code in question is below.
initComplete: function () {
this.api().columns().every(function () {
var column = this;
var select = $('<select class="form-control" style="margin-left:-25px;width: 150%" "><option value="">'+column.header().textContent+'</option></select>')
.appendTo($(column.header()).empty())
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
}
Looking at other articles, I need to optimize. What should I do in my case? I hope a good solution.
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has accepted answers - jump to:
Answers
Do you get errors in the browser's console?
Can you post a link to your page or a test case showing the problem so we can help debug?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Here it s.
http://live.datatables.net/wuhikude/1/
Thank you. I've taken a look and there is most definitely a bug there. I'm not immediately sure what is causing the issue though - I will take a look and report back tomorrow.
Allan
I've just committed a fix for this issue. It was caused by a dodgy regex which I've not replaced with something a bit more simple (although it doesn't cover as many use cases).
With the nightly your example will now work: http://live.datatables.net/wuhikude/5/edit .
Do note though that the HTML stripping will leave the <option> strings from your header. You'll need to use an output formatter to correctly extract just the selected value.
Allan
Thanks for any help. However, when downloading as an Excel file, not only the title of the select bar in the header but also the data below are entered into Excel. Can't we just print the header title?
The best way is to use two headers. One for the search inputs and the other for the title and sorting. See this example from this thread to see one way to do this. Note the use of
orderCellsTop
.Kevin
Thanks for the answer. Finally, I'll ask you one more question. I am currently using Responsive, but the hidden columns are not displayed when exporting. How do I export hidden columns as well?
By default all columns will be exported, see this example:
http://live.datatables.net/yiqigaqu/1/edit
Please post a link to your page or provide an example (update mine) showing the problem so we can help debug.
Kevin