DataTables search child row content and child row field name ?

DataTables search child row content and child row field name ?

matt.crawfoordmatt.crawfoord Posts: 31Questions: 13Answers: 0
edited June 2016 in Free community support

hi all,
The DataTables search bar does not let me search for content within child rows content and child rows field name .
because the child row field name is dynamic ,so how can i search for content with child rows content and child rows field name ??

I tried the solution, by adding the javascript function ..but it still doesn't work,

       <script>
         ......
      table.columns().every( function () {
       var that = this;
      var header = this.header();
        $( 'input', this.footer() ).on( 'keyup change', function () {
        that.column( header.getAttribute('data-search-index')*1 ) // *1 to make it a number
        .search( this.value ).draw();
           } );
         } );
        </script>
            <table id="example" class="display" cellspacing="0" width="100%">
              <thead>
                <tr>
                  <th ></th>
                  <th data-search-index="3">datetime</th>
                  <th data-search-index="3">message</th>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <th></th>
                  <th>datetime</th>
                  <th>message</th>
                </tr>
              </tfoot>
            </table>

Can someone please help me out?

Thanks

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    You would have to add the content of the child rows into a column of the table that the DataTable can search. As you say the child row content is dynamic so there is no way DataTables and search it.

    Allan

  • matt.crawfoordmatt.crawfoord Posts: 31Questions: 13Answers: 0
    edited July 2016

    hi allan,
    from my code , i have add

      table.columns().every( function () {
         var that = this;
         var header = this.header();
         $( 'input', this.footer() ).on( 'keyup change', function () {
         that.column( header.getAttribute('data-search-index')*1 ) // *1 to make it a number
        .search( this.value ).draw();
              } );
        } );
    

    but still can't search child row , What are any potential errors that I am overlooking?

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Without a test case it is impossible to say, but I don't really see form the above code how that addresses the point I made above. Does that include the data that should be searchable in a hidden column?

    Allan

  • matt.crawfoordmatt.crawfoord Posts: 31Questions: 13Answers: 0

    hi allan,
    how to include the data in a hidden column?

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    It depends on how you are generating your table. Assuming it is in the data source object for the row you would just include it like any other data.

    Again, it is virtually impossible to say without a test case showing me how you are using DataTables.

    Allan

  • matt.crawfoordmatt.crawfoord Posts: 31Questions: 13Answers: 0

    hi allan,

    my json output is looks like as below, each key and value is different ,datetime and message is parent row the others is child row ,I am new to datatable, can you give me an example about it ?

      "aaData": [   
         {
            "datetime":"2016-06-17T10:00:05.005Z",
             "message":"................",
           "servlet-name":"cofaxCDS",
            "servlet-class":"org.cofax.cds.CDSServlet",
             "configGlossary":"Philadelphia, PA",
               "configGlossary":"ksm@pobox.com",
              "configGlossary": "Cofax",
              "configGlossary":"/images/cofax.gif",
              "configGlossary":"/content/static",
             "templateProcessorClass": "org.cofax.WysiwygTemplate",
             "templateLoaderClass": "org.cofax.FilesTemplateLoader",
             "templatePath": "templates",
             "defaultListTemplate": "listTemplate.htm",
             "defaultFileTemplate": "articleTemplate.htm"
             },
        {
             "datetime":"2016-06-17T10:00:05.005Z",
             "message":"................",
              "log": 1,
              "logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
             "logMaxSize": "",
             "dataLog": 1,
             "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
            "dataLogMaxSize": "",
            "removePageCache": "/content/admin/remove?cache=pages&id=",
            "removeTemplateCache": "/content/admin/remove?cache=templates&id=",
            "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
        },....]
    
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    I am new to datatable, can you give me an example about it ?

    Sure - the priority support options are available here.

    If you give a link to a test case I could take a look at it.

    Allan

This discussion has been closed.