Individual column searching not searching for render data

Individual column searching not searching for render data

neesaneesa Posts: 2Questions: 1Answers: 0

I want to do individual column searching on column Address & History Order which are using render function but it doesn't show any result. It shows "No matchings record found". I retrieve the data from server side.

Here's my test case: https://live.datatables.net/yalesali/5/edit

     $(document).ready(function() {

      $('#example tfoot th').each(function() {
        var title = $(this).text();
        $(this).html('<input type="text" placeholder="Search ' + title + '" />');
      });

      var dt = $('#example').dataTable({

        initComplete: function() {
          var api = this.api();

          api.columns().every(function() {
            var that = this;

            $('input', this.footer()).on('keyup change', function() {
              if (that.search() !== this.value) {
                that
                  .search(this.value)
                  .draw();
              }
            });
          });
        },

        "processing": true,
        "serverSide": true,
        "ajax": {
          "url": "server_processing.php",
          "data": function(data) {
            return data;
          },
          "dataSrc": function(json) {
            console.log(json);
            return json.data;
          }
        },
        "columns": [{
            "data": 'ID_No'
          },
          {
            "data": null,
            "render": function(data, type, row, meta) {

              var address = row["Address"] ? row["Address"] : " ";
              var address2 = row["Address_2"] ? row["Address_2"] : " ";

              return row["Address"] + " " + address2;
            }
          },
          {
            "data": null,
            "render": function(data, type, row) {
              var total1 = parseFloat(row.total1) || 0;
              var total2 = parseFloat(row.total2) || 0;
              var totals = total1 + total2;
              return totals;
            }
          }

        ],
      });
    });

How to solve this issue? Any help would be appreciated.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It's because you've enabled serverSide - this means all the searches (and ordering and paging) are performed on the server, not the client. The server wouldn't know how the data has been rendered on the client, so it can only use the source data. If you've got less that 10k records, it's unlikely that you'll need server-side processing, so one option perhaps would be to remove that serverSide setting.

    Colin

  • neesaneesa Posts: 2Questions: 1Answers: 0
    edited March 2023

    Hi @colin. I need to use the server side because my data around 100,000k. Is there another way aside from disable the serverSide?

  • allanallan Posts: 63,451Questions: 1Answers: 10,465 Site admin

    Yes, you need to perform the required filtering in your server-side script. Your rendering is currently on the client-side, which of course the server-side can't search, since it knows nothing about that.

    If you want to search formatted data, you need to format it at the point where it is being searched. In this case, I presume you are using the demo SSP class - so what you would probably need to do is create a VIEW that does the string concatenation you need, and then point the SSP class at that.

    Allan

Sign In or Register to comment.