Sorting on unique link text

Sorting on unique link text

ronr1999ronr1999 Posts: 1Questions: 1Answers: 0
edited October 2018 in Free community support

I'm doing:

        this.api().columns([1]).every( function () {
            var column = this;
            var select = $('<select><option value="">Brands</option></select>')
            .appendTo( $(column.header()).empty() )
            .on( 'change', function () {
                var val = $.fn.dataTable.util.escapeRegex(
                    $(this).val()
                );

                column
                .search( val ? '^'+val+'$' : '', true, true )
                .draw();
            } );

            column.data().unique().sort().each( function ( d, j ) {
                // "d" IS A LINK, GET THE TEXT ONLY
                d = $(d).text();
                select.append( '<option value="'+d+'">'+d+'</option>' )
            } );
        } );

But... I want unique.sort on just the .text of the link. Can I give unique() options to use only the text?

Thanks! I'm fairly new to this...

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @ronr1999 ,

    Yep, you can add anything into that select list. You would want to parse the string to get just the text on line 17, then you may also need to modify what you search for (if you need to reconstruct the original string) on line 10.

    Cheers,

    Colin

This discussion has been closed.