Issues with Column Control and Column Reorder in State object

Issues with Column Control and Column Reorder in State object

mspenskimspenski Posts: 4Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I am using the latest libraries and noticing 2 issues both of which are tied to the state not being updated properly to reflect the current state of the table.

  1. When i have individual search boxes using the column control search funtionality, when I type search text into the search field in column[2] the search text shows in the column control search for column[0] in the state object. I had to implement a cutom mapping function to correctly map the search to the correct column in the State object.

  2. When reordering columns, the columncontrols in the state object do not get updated to the correct indexes that they should be. In the state object below it shows that columns 7 and 4 should be search lists not search inputs. columns 5 & 6 should be search inputs. but if you look at the colReorder and the columnControl they do not align with the correct indexes. This is causing issues for the workaround I implemented for issues 1 because the column control data does not align correctly to the indexes in the colReorder.

    "colReorder": [
    0,
    1,
    2,
    3,
    7,
    5,
    6,
    4,
    8,
    9,
    10,
    11
    ],
    "columnControl": {
    "2": {
    "searchInput": {
    "logic": "greater",
    "type": "date",
    "value": "2/1/2020"
    }
    },
    "3": {
    "searchList": []
    },
    "4": {
    "searchInput": {
    "logic": "contains",
    "type": "text",
    "value": "acc"
    }
    },
    "5": {
    "searchList": []
    },
    "6": {
    "searchInput": {
    "logic": "contains",
    "type": "text",
    "value": "rn"
    }
    },
    "7": {
    "searchList": []
    },
    "8": {
    "searchInput": {
    "logic": "less",
    "type": "date",
    "value": "2/1/2024"
    }
    },
    "10": {
    "searchList": []
    },
    "11": {
    "searchList": []
    }
    },

Answers

  • mspenskimspenski Posts: 4Questions: 1Answers: 0

    for reference this is the mapping function i had to implement the state save to correctly map the state column control data (but again this relies on the column controls being aligned with the colReorder which is not)

    TaskDashboard.prototype.MapStateSaveDataFromColumnControl = function (data) {
        data.columns.forEach(col => {
            col.search.search = "";
        });
    
        // Iterate through the columnControl state (which holds the values from the search inputs)
        for (var visibleIndex in data.columnControl) {
            if (data.columnControl.hasOwnProperty(visibleIndex)) {
    
                var colState = data.columnControl[visibleIndex];
    
                // Check for a search input value
                if (colState.searchInput && colState.searchInput.value) {
                    // data.colReorder[visibleIndex] gives the original column index
                    var originalIndex = data.colReorder[visibleIndex];
    
                    //Write the search value to the correct original column in the standard 'columns' array
                    if (data.columns[originalIndex]) {
                        data.columns[originalIndex].search.search = colState.searchInput.value;
                    }
                }
            }
        }
    },
    
  • allanallan Posts: 65,339Questions: 1Answers: 10,838 Site admin

    Can you link to an example showing the issue please?

    Many thanks,
    Allan

Sign In or Register to comment.