I assume you're using the Tablesorter plugin? This should work.

var headers = {};
$('#table thead th').each(function(index){
    if (index > 2)
        headers[index] = { sorter: false };
});

$("#table").tablesorter({
    headers: headers
});

You can also disable headers using metadata, with a more concise
syntax:

$('#table thead th:lt(3)').addClass('{sorter: false}');

see http://docs.jquery.com/Selectors/lt#index

- ricardo





On Jan 21, 8:21 pm, shinobi <mattia.bargell...@gmail.com> wrote:
> Hi everybody.
> I have an html table with a fixed number columns (or headers) and a
> variable number of columns, that may vary in numbers depending on data
> in the DB.
>
> I want to make sortable one or two columns of the fixed ones, so I
> would like to know how to loop through the headers object in order to
> set to "sorter:false" all the headers that I want to be UN-sortable.
>
> In other words, something like:
>
> for(i=0;i<colNum;i++) {
>     if(i != x) {
>         headers: { i: {sorter: false} }
>    }
>
> }
>
> where x is the index I want to be sortable.
>
> Sorry for my stupid question, but me and javascript aren't good
> friends :(
>
> Thanks in advance for any answer.
>
> Mattia (Italy)

Reply via email to