YADCF with searchBuilder - ColReorder error when dynamic data

YADCF with searchBuilder - ColReorder error when dynamic data

OnLogOnLog Posts: 18Questions: 6Answers: 1

Hi.

I have table with dynamic data. When using YADCF, searchBuilder and colReorder I got error: can't access property "mData", N.aoColumns[l] is undefined, when reordering the columns. The error seams to come from YADCF.

It works when:
- I turn off YADCF
- or removing searchBuilder
- or have static data direct in my HTML

In this test case I get error, but still it seem like the colReorder is working, however, in my main project, the order get messed up. Am I missing somthing in the dynamic data setup?

Test case:
https://jsfiddle.net/supernova404/9fdsr5cj/216/

Answers

  • OnLogOnLog Posts: 18Questions: 6Answers: 1

    For the record I'm using this versions:
    - dataTables 1.13
    - YADCF 0.9.6
    - SearchBuilder 1.6.0
    - ColReorder 1.7.0

  • kthorngrenkthorngren Posts: 21,545Questions: 26Answers: 4,988
    edited January 2

    The problem is you have 5 Datatable columns defined:

    colsTable.push({
        title: 'Name',
        data: 'name'
      });
      colsTable.push({
        title: 'Position' ,
        data: 'position'
      });
      colsTable.push({
        title: 'Office' ,
        data: 'office'
      });
      colsTable.push({
        title: 'Age',
        data: 'age'
      });
      colsTable.push({
        title: 'Salary',
        data: 'salary'
      });
    

    But you have defined 6 columns in YADCF:

    yadcf.init(table, [{
                                column_number: 0
                            }, {
                                column_number: 1,
                      filter_default_label: 'Name',
                            }, {
                                column_number: 2,
                      filter_default_label: 'Position',
                            }, {
                                column_number: 3,
                                filter_type: "auto_complete",
                                text_data_delimiter: ",",
                      filter_default_label: 'Office',
                            }, {
                                column_number: 4,
                      filter_default_label: 'Age'
                                //filter_type: "date"
                            }, {
                                column_number: 5,
                      filter_default_label: 'Salary'
                            
                            }]);
    

    The first column starts at index 0. column_number: 0 is the Name column. The addition YADCF column is causing the error:

    Uncaught TypeError: Cannot read properties of undefined (reading 'mData')

    Kevin

  • OnLogOnLog Posts: 18Questions: 6Answers: 1

    I see there was a misstake inn my test case, sorry about that. I thought I had managed to reproduce the problem. In my main project I had this error everytime I moved my columns 2 or more places (move one place -> no error). But apperently my test was working. I figured out that in my .cshtml file I had this functions running:

    $('#example').DataTable().clear().destroy();
    $('#example tbody').empty();
    $('#example').empty();
    

    Removing this and no error.

    Thanks for your time!

Sign In or Register to comment.