0

Is there a way to sort multiple tables that share the same id? Unfortunately I can't use classes or unique id's for this.

$('#fixed-columns-table').tablesorter({
    theme: uid,
    showProcessing: true,
    headerTemplate: '{content} {icon}',
    //dateformat : "mmddyyyy",
    dateformat: "yyyymmdd",
    widgets: ['uitheme', 'zebra', 'filter', 'stickyHeaders', 'scroller'],
    widgetOptions: {
        scroller_upAfterSort: true,
        scroller_jumpToHeader: true,

        scroller_height: 300,
        scroller_fixedColumns: startFixedColumns,
        scroller_addFixedOverlay: false,
        scroller_rowHighlight: 'hover',
        scroller_barWidth: null,

        // jQuery selector or object to attach sticky header to
        stickyHeaders_attachTo: '.wrapper_Table' // or $('.wrapper')
    }
});

I tried the answers on previously asked Questions with similar problems, but none of them have worked.

  • 1
    Guess you already know this, but ID must be unique. So you need to find a way to change it or set a class else it will be hard – Carsten Løvbo Andersen Aug 18 '23 at 09:35
  • @CarstenLøvboAndersen Yes, I am aware of this. Unfortunately, the project reuires me to use the same id on every table. Thanks anyways. – Leon Hoffmann Aug 18 '23 at 09:38
  • Doesn't change the fact, that using the ID selector you will always only ever get the first element. Try the alternative mentioned in the duplicate, using the attribute selector instead. – CBroe Aug 18 '23 at 09:40
  • @CBroe I just tried, but it doesn't work for me either. I guess I'll have to find a way to be allowed to change the id. Thanks – Leon Hoffmann Aug 18 '23 at 09:47
  • Maybe the tablesorter doesn't allow initialization on multiple elements at once? You could try and loop over the elements selected via attribute selector, and then initialize it for each one individually (not by selecting via ID again then obviously.) – CBroe Aug 18 '23 at 09:55
  • @CBroe That's what I tried. I will ask my boss to change the project requirements so I can change the ids or maybe even rely on classes. Still tank u – Leon Hoffmann Aug 18 '23 at 09:57
  • Is the ID used for anything else - selection by other scripts, selection to apply formatting in style sheet rules? If not, you could walk over the elements and _change_ their ID (for example adding a counter suffix), before you initialize the tablesorter on them. – CBroe Aug 18 '23 at 10:03
  • @CBroe no, but the goal of the code is to rely on an id to apply the function to everything in the system. I got it to change a bit tho – Leon Hoffmann Aug 18 '23 at 11:18

0 Answers0