ServerSide filtering and null data

ServerSide filtering and null data

INTONEINTONE Posts: 153Questions: 58Answers: 6
edited October 2014 in Editor

If if turn on server side Processing and try to filter on a table that has a column that has a null value it triggers and error :

Here is my code:

          $('#view_affiliates_details').DataTable( {
                     dom: "Tfrtip",
                    ajax: {
                        url: "../php/affiliates.php",
                        type: "POST"
                    },
                    serverSide: true,
                    columns: [
                        { data: "affiliates.name" },
                        { data: "affiliates.contact_email" },
                        { data: "affiliates.contact_mobile_number" },
                        { data: "affiliates.contact_number_2" }  ,
                        {
                          data: null,
                          className: "center",
                          defaultContent: '<a href="#" class="editor_edit button blue">Edit</a> <a href="#" class="editor_remove button red">Delete</a>'
                        }  
                    ],
                    tableTools: {
                        sRowSelect: "os",
                        aButtons: [
                            { sExtends: "editor_create", editor: editor },
                            { sExtends: "editor_edit",   editor: editor },
                            { sExtends: "editor_remove", editor: editor }
                        ]
                    },

                    initComplete: function ( settings, json ) {
                        editor.field( 'affiliates.company_branches_id' ).update( json.company_branches );
                    }
                } );

When I do a simple filter I get an error that unknown field index(4). If I remove the server side processing i am able to filter. How can this be fixed?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    The error should link you to this tech note. There are details there, but basically if you have null data, you need to tell DataTables what to do with it. columns.defaultContent can be used for this.

    Allan

  • INTONEINTONE Posts: 153Questions: 58Answers: 6
    edited October 2014

    Thank you. I have fixed it doing this:

              {
                data: null,
                className: "center",
                defaultContent: '<a href="#" class="editor_edit button blue">Edit</a> <a href="#" class="editor_remove button red">Delete</a>',
               targets: -1
    
    
                  } 
    
  • INTONEINTONE Posts: 153Questions: 58Answers: 6
    edited October 2014

    I am sorry Alan. I blundered. During other tests I realized that the code above did not fix the issue. You suggested I use the columns.defaultContent , which I am already using but still experiencing the same error:

      {
    data: null,
    className: "center",
    defaultContent: '<a href="#" class="editor_edit button blue">Edit</a> <a    href="#" class="editor_remove button red">Delete</a>',
        targets: -1
    
    
      }
    
  • INTONEINTONE Posts: 153Questions: 58Answers: 6
    edited October 2014

    I found the answer from a similar post that was answered recently here:
    http://datatables.net/forums/discussion/24231/null-column-serverside-search-error#latest

    its amazing how simple it is to implement some of these features. However finding the correct reference some times is difficult. Answer:

             {
               data: null,
               className: "center",
               defaultContent: '<a href="#" class="editor_edit button blue">Edit</a> <a    href="#" class="editor_remove button red">Delete</a>',orderable: false, "bSearchable": false
    
                }
    
  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Good to hear you got it working.

    I would be interested to know if you have any suggestions on how I can improve the documentation for finding answers. Obviously I know where to look since I wrote it, so any feedback would be welcome.

    Allan

This discussion has been closed.