koalyptus / TableFilter

A Javascript library making HTML tables filterable and a bit more :)
https://www.tablefilter.com
MIT License
324 stars 95 forks source link

Add row number column #828

Closed punx120 closed 1 year ago

punx120 commented 2 years ago

Hi

Thanks for the great library, is there currently a way to display the row number automatically? especially after sorting?

Thank you.

punx120 commented 2 years ago

Ended up doing something a bit ugly:

       tf.emitter.on(['initialized'], parseRows);
        tf.emitter.on(['column-sorted'], (tf, sc, desc) => parseRows(tf));
        tf.init();
        // var stylesheet = tf.getStylesheet('default');
        // stylesheet.href = tf.themesPath + 'transparent/transparent.css'
        function parseRows(tf) {
            var cellIndex = 0; // POP column
            var rowsIdx = tf.getValidRows();
            rowsIdx.forEach(function(idx){
                var row = tf.dom().rows[idx];
                var cell = row.cells[cellIndex];
                cell.innerHTML = idx - 1
            });
        }
koalyptus commented 1 year ago

Well done, that's the idea: leverage the as much as possible the many hooks provided by the library 👍