Sorting on unique link text

Sorting on unique link text

ronr1999ronr1999 Posts: 1Questions: 1Answers: 0
edited October 15 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: 2,773Questions: 0Answers: 482

    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

Sign In or Register to comment.