Custom Filter with Re-ordered Columns

Custom Filter with Re-ordered Columns

jsosajsosa Posts: 14Questions: 4Answers: 0

When using custom filtering, is there a way to use named columns? I used column keys, but the custom filters don't work correctly if someone re-orders the columns. Or is there a way to make the custom filters always use a specific column even when columns are re-ordered?

This question has an accepted answers - jump to answer

Answers

  • jsosajsosa Posts: 14Questions: 4Answers: 0

    Note, I have it set up with ajax, and set columns like columns: [ { "name": "id", "data": "id"} ], but I only see an array with keys when using $.fn.dataTable.ext.search.push

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Looks like you can use colReorder.order() to get the current column order. This can be used as the index to searchData for the search plugin. For example:
    http://live.datatables.net/juxukoda/1/edit

    No matter what order the columns are in the plugin will print the name column.

    Kevin

  • jsosajsosa Posts: 14Questions: 4Answers: 0

    Trying your example, if I move the name column to the right, it starts printing different values instead of names. Like if I move Name col over to where Office is, such that it's Position, Office, Name, it starts printing Office values instead of Name values.

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited October 2020 Answer ✓

    I see. Looks like searchData[colOrder.indexOf(0)] is needed instead of searchData[colOrder[0]].

    http://live.datatables.net/juxukoda/2/edit

    Kevin

  • jsosajsosa Posts: 14Questions: 4Answers: 0

    That works! Thank you very much for your help!

This discussion has been closed.