2016-12-18 10 views
1

したがって、colReorderと一緒にjqueryデータ型を使用してテーブルを設定しています。この表には、列ヘッダーをクリックして切り替える列を選択する方法など、いくつかの機能があります。この機能を動作させるためには、colReorderを有効にしなければなりませんでした。唯一の問題は今、私のすべての列はドラッグ可能です。これをどうすれば解決できますか?jqueryデータテーブルのドラッグアンドドロップを無効にする方法

ここで私が間違ってやっているお聞かせください偽

bsortableをfalseに設定

  • bsortをfalseに設定
  • draggableを設定する私は

    • を試みたものです。また、ここに私のコンストラクタです:

       window.table = 
           $table.DataTable({ 
            data: window.apiData['data'], 
            /** 
            dat 
            * Specify which columns we're going to show 
            */ 
            columns: window.columnMapping, 
            /** 
            * we want to disable showing page numbers, but still limit the number of results 
            */ 
            dom: "t", 
            /** 
            * let's disable some dynamic custom css 
            */ 
            asStripClasses: [], 
            /** 
            * let's keep the pages reasonable to prevent scrolling 
            */ 
            pageLength: 8, 
      
            /** 
            * this helps with hotswapping columns 
            */ 
            colReorder: true 
           }); 
      

      ありがとう!

  • 答えて

    2

    ColReordersイベントバインディングを<th>要素に上書きすることができます。幸いなことに、イベントはネームスペースで充実しているため、簡単に追跡することができ、ColReorder.mousedownは列のドラッグをトリガーする役割を果たします。だから、

    function resetColReorderMD() { 
        $('.dataTable thead th').each(function() { 
        var md = $._data($(this)[0]).events.mousedown; 
        for (var i=0, l=md.length; i<l; i++) { 
         if (md[i].namespace == 'ColReorder') { 
         md[i].handler = function() {} 
         } 
        } 
        }) 
    } 
    
    $('#example').DataTable({ 
        colReorder: true, 
        initComplete: function() { 
        resetColReorderMD() 
        } 
    }) 
    

    デモによって機能をリセットすることができます - >http://jsfiddle.net/2y4w3v6g/

    ColReorderプラグインを使用している場合、列の並べ替えを無効にすると、むしろ無意味に思えます。私は、上記の「機能」がColReorder機能を大量に使用していると推測していますが、これが実際の問題です。上記は推奨されないハックとみなすべきです。

    +0

    私の場合は、 '$( 'dataTable')の'((。dataTable thead th ')をそれぞれの(function(){...}) 'に置き換えなければなりません。 ().header())。each(function(){...}) '。ありがとうございました。 – eXe

    関連する問題