代码之家  ›  专栏  ›  技术社区  ›  tree em

动态jquery表排序

  •  1
  • tree em  · 技术社区  · 14 年前

    我正在使用 http://tablesorter.com/docs/example-options-headers.html

     $("#sort-table").tablesorter( 
           {headers: { 
    
                0: { 
                    sorter: false 
                   }, 
    
                dynamic_value: { 
                         sorter: false 
                 } 
            } 
        });
    

    如何从$('.header').length传递动态_值?

    <thead>
      <tr>
           <th width="20"><?php echo $check;?></th>
           <th class="header">FullName</th>
           <th class="header">Rank</th>
           <th class="header">Email</th>
           <th class="header">Position</th>
           <th width="15"></th>
        </tr>
    

    2 回复  |  直到 12 年前
        1
  •  4
  •   MvanGeest    14 年前

    我想你想申请 sorter: false 必须动态计算数字的某一列。据我所知,javascript不允许使用任何直接语法,因此您必须遵循以下步骤:

    headerset = {
                   0: { 
                        sorter: false 
                   }
                // any other static column here
                };
    // repeat the following line for each dynamic value
    headerset[dynamicvalue] = { sorter: false };
    // the variable headerset now contains the header settings
    // you can apply them to the tablesorter
    $("#sort-table").tablesorter({ headers: headerset });
    

    它不雅致,但应该管用。

        2
  •  0
  •   kratenko Tinku George    12 年前

    以上查询的解决方案如下:

    $(document).ready(function() 
    { 
        // extend the default setting to always sort on the first column
        $.tablesorter.defaults.sortList = [[0,0]];
        var newheader={
            1:{sorter:false},
            4:{sorter:false}
        };
        $(".tablesorter").tablesorter({headers:newheader});
    });
    

    我们还可以使用JSON字符串扩展选项,如图所示。 我已经创建了一个打开解决方案的容器 http://codebins.com/codes/home/4ldqpcd