Disable table column sorting when ($(#addData).is(:"visible"))

salmon eater

I want to disable table column sorting whenever #addData is visible but when I apply if ($("#addData").is(":hidden")) to the .each() function, it does not work.

Is there a way to do it?

Here is the table sorting code:

$('th:contains(Remote), th:contains(Interval),th:contains(Last), th:contains(Active)')
    .each(function(){

        var th = $(this),
            thIndex = th.index(),
            inverse = false;  

        th.click(function(){

            table.find('td').filter(function(){

                return $(this).index() === thIndex;

            }).sortElements(function(a, b){

                return $.text([a]) > $.text([b]) ?
                    inverse ? -1 : 1
                    : inverse ? 1 : -1;

            }, function(){

                // parentNode is the element we want to move
                return this.parentNode; 

            });

            inverse = !inverse;

        }); 

    });


jQuery.fn.sortElements = (function(){

    var sort = [].sort;

    return function(comparator, getSortable) {

        getSortable = getSortable || function(){return this;};

        var placements = this.map(function(){

            var sortElement = getSortable.call(this),
                parentNode = sortElement.parentNode,

                // Since the element itself will change position, we have
                // to have some way of storing its original position in
                // the DOM. The easiest way is to have a 'flag' node:
                nextSibling = parentNode.insertBefore(
                    document.createTextNode(''),
                    sortElement.nextSibling
                );

            return function() {

                if (parentNode === this) {
                    throw new Error(
                        "You can't sort elements if any one is a descendant of another."
                    );
                }

                // Insert before flag:
                parentNode.insertBefore(this, nextSibling);
                // Remove flag:
                parentNode.removeChild(nextSibling);

            };

        });

        return sort.call(this, comparator).each(function(i){
            placements[i].call(getSortable.call(this));
        });

    };

})(); 
cgatian

Add the visiblity check to the click event called on the th. This can be made a little more performant if you store #addData in a variable within the each.

$('th:contains(Remote), th:contains(Interval),th:contains(Last), th:contains(Active)')
    .each(function(){

        var th = $(this),
            thIndex = th.index(),
            inverse = false;  
        //BOOSTIE: var addData = $('#addData');
        th.click(function(){
            //BOOSTIE: if(addData.is(':hidden'))
            if($("#addData").is(":hidden")) //Check to see if its visible
            {   
              table.find('td').filter(function(){

                  return $(this).index() === thIndex;

              }).sortElements(function(a, b){

                  return $.text([a]) > $.text([b]) ?
                      inverse ? -1 : 1
                      : inverse ? 1 : -1;

              }, function(){

                  // parentNode is the element we want to move
                  return this.parentNode; 

              });

              inverse = !inverse;
            }
        }); 

    });

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Sorting Sql Table by combining multiple column as a column

分類Dev

Angular Material table is sorting only by last column

分類Dev

Column sorting not working when using custom HeaderView

分類Dev

jqgrid: MySQL specific problems when sorting a date column

分類Dev

disable sorting in lineChart series in Primefaces?

分類Dev

Sorting a bigint[] column in PostgreSQL

分類Dev

Sorting matrix by column names

分類Dev

Pivot table sorting pandas

分類Dev

Sorting not enable in my table

分類Dev

($(#addData).is(: "visible"))の場合、テーブルの列の並べ替えを無効にします

分類Dev

Sorting rows without showing sorting column

分類Dev

How to disable sorting in an Excel shared workbook

分類Dev

postgres is ignoring "-" when sorting

分類Dev

"ORA-22812: cannot reference nested table column's storage table" when trying to access system table

分類Dev

Add sorting function on table tag

分類Dev

Triggering Code when a specific value is inserted into a table column in an Azure SQL Table

分類Dev

Making a column in a TableView not visible until requested

分類Dev

Ignore nil elements when sorting

分類Dev

Table scrolling behind sticky header is visible

分類Dev

Problems with sorting datetime column of DataTables Angular

分類Dev

sorting data frame and calculating instant value of a column

分類Dev

Sorting values between column using pandas

分類Dev

2 dimensional array sorting using column index

分類Dev

Mat-table Sorting Demo not Working

分類Dev

JQuery Table Sorting - More Efficient way?

分類Dev

Sorting columns in HTML table using Rails or Bootstrap?

分類Dev

Table sorting doesn't work with IsotopeJs

分類Dev

SQL (and JPA) Sorting parameters on a denormalised table

分類Dev

Table sorting based on the number of occurrences of a particular item

Related 関連記事

  1. 1

    Sorting Sql Table by combining multiple column as a column

  2. 2

    Angular Material table is sorting only by last column

  3. 3

    Column sorting not working when using custom HeaderView

  4. 4

    jqgrid: MySQL specific problems when sorting a date column

  5. 5

    disable sorting in lineChart series in Primefaces?

  6. 6

    Sorting a bigint[] column in PostgreSQL

  7. 7

    Sorting matrix by column names

  8. 8

    Pivot table sorting pandas

  9. 9

    Sorting not enable in my table

  10. 10

    ($(#addData).is(: "visible"))の場合、テーブルの列の並べ替えを無効にします

  11. 11

    Sorting rows without showing sorting column

  12. 12

    How to disable sorting in an Excel shared workbook

  13. 13

    postgres is ignoring "-" when sorting

  14. 14

    "ORA-22812: cannot reference nested table column's storage table" when trying to access system table

  15. 15

    Add sorting function on table tag

  16. 16

    Triggering Code when a specific value is inserted into a table column in an Azure SQL Table

  17. 17

    Making a column in a TableView not visible until requested

  18. 18

    Ignore nil elements when sorting

  19. 19

    Table scrolling behind sticky header is visible

  20. 20

    Problems with sorting datetime column of DataTables Angular

  21. 21

    sorting data frame and calculating instant value of a column

  22. 22

    Sorting values between column using pandas

  23. 23

    2 dimensional array sorting using column index

  24. 24

    Mat-table Sorting Demo not Working

  25. 25

    JQuery Table Sorting - More Efficient way?

  26. 26

    Sorting columns in HTML table using Rails or Bootstrap?

  27. 27

    Table sorting doesn't work with IsotopeJs

  28. 28

    SQL (and JPA) Sorting parameters on a denormalised table

  29. 29

    Table sorting based on the number of occurrences of a particular item

ホットタグ

アーカイブ