Datatable 'Search" box

Datatable 'Search" box

larrybglarrybg Posts: 14Questions: 5Answers: 0

My datatable accepts JSON to populate data. Everything is shown fine. The data is the survey results, and some of the fields are empty because they are not required, so my table has few rows where data is not in every column.
It looks like "Search" box is ignoring data from such columns where data is missing. For example, if I have a column with data in all rows I can filter/search them with no problem, and the next column is missing data in the first row or another row - I cannot find anything from there.

I'm sorry, hope my explanation makes sense.
My code:

                        $('#dataTable').DataTable({
                                "data": data,
                                "columns": columns,
                                "dom": 'Blfrtip',
                                buttons: [
                                    {
                                        extend: 'excelHtml5',
                                        title: 'Survey Results - ' + surveyName
                                    },
                                    {
                                        extend: 'csvHtml5',
                                        title: 'Survey Results - ' + surveyName
                                    },
                                    {
                                        extend: 'pdfHtml5',
                                        title: 'Survey Results - ' + surveyName
                                    },
                                    {
                                        extend: 'copyHtml5',
                                        title: 'Survey Results - ' + surveyName
                                    },
                                ]
                            });

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Hard to say without seeing your data and trying to search for it. Can you create a simple test case with en example of your data and column config?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • larrybglarrybg Posts: 14Questions: 5Answers: 0

    Hi Kevin,
    Here is the example with some data: http://live.datatables.net/zugerevi/1/edit?html,js,output
    There are two columns where data is missing in some rows, try to search words "Bootstrap" or "AngularJS

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Great, thanks. The data in those columns are arrays. Not sure how Datatables sees them internally but they aren't strings so searching them doesn't appear to work. However you can render that data into a comma separated list then search. See the updated example:
    http://live.datatables.net/zugerevi/2/edit

    I added an array element to the AngularJS array and you can search for both options.

    Kevin

  • larrybglarrybg Posts: 14Questions: 5Answers: 0

    Yeah, I see it's working. But I never know how many columns will be there, so the "targets" in the "columnDefs" must be dynamic.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You can use the render option in your columns variable instead of columnDefs. The script building the columns will need to know which columns contains arrays of data.

    Kevin

This discussion has been closed.