How to detect last visible column in responsive state of Datatables












0














I want to detect last visible column in responsive Datatables. My target is to add border-right on hover state of each row.



As last-child doesn't work, I've tried CSS selector tr:hover td:visible:last, but it's not working.



Is there any solution where I can get visible columns and add class on visible TD? So I can apply CSS using :last-of-type



enter image description here










share|improve this question
























  • You want to match the last cell before the hidden one, or all visible cells?
    – Salman A
    Dec 26 '18 at 9:00
















0














I want to detect last visible column in responsive Datatables. My target is to add border-right on hover state of each row.



As last-child doesn't work, I've tried CSS selector tr:hover td:visible:last, but it's not working.



Is there any solution where I can get visible columns and add class on visible TD? So I can apply CSS using :last-of-type



enter image description here










share|improve this question
























  • You want to match the last cell before the hidden one, or all visible cells?
    – Salman A
    Dec 26 '18 at 9:00














0












0








0







I want to detect last visible column in responsive Datatables. My target is to add border-right on hover state of each row.



As last-child doesn't work, I've tried CSS selector tr:hover td:visible:last, but it's not working.



Is there any solution where I can get visible columns and add class on visible TD? So I can apply CSS using :last-of-type



enter image description here










share|improve this question















I want to detect last visible column in responsive Datatables. My target is to add border-right on hover state of each row.



As last-child doesn't work, I've tried CSS selector tr:hover td:visible:last, but it's not working.



Is there any solution where I can get visible columns and add class on visible TD? So I can apply CSS using :last-of-type



enter image description here







jquery css datatables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 26 '18 at 9:18









john

1,50751827




1,50751827










asked Dec 26 '18 at 8:54









Faisal Janjua

184




184












  • You want to match the last cell before the hidden one, or all visible cells?
    – Salman A
    Dec 26 '18 at 9:00


















  • You want to match the last cell before the hidden one, or all visible cells?
    – Salman A
    Dec 26 '18 at 9:00
















You want to match the last cell before the hidden one, or all visible cells?
– Salman A
Dec 26 '18 at 9:00




You want to match the last cell before the hidden one, or all visible cells?
– Salman A
Dec 26 '18 at 9:00












2 Answers
2






active

oldest

votes


















0














You can detect Window resize, and DOM change events using domsubtreemodified and window resize event. You can't do this using pure css, as you can not combine :not and :style selector together






$(window).resize(function(){
$('td:visible:last').css('color', 'red');
});
$(document).ready(function(){
$('td:visible:last').css('color', 'red');
});
$('table , table td').on("DOMSubtreeModified",function(){
$('td').css('color', 'black');
$('td:visible:last').css('color', 'red');
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<td>Home1</td>
<td>Home2</td>
<td>Home3</td>
<td style="display:none">Home4</td>
<td style="display:none">Home5</td>
<td style="display:none">Home6</td>
</tbody>
</table>








share|improve this answer



















  • 1




    Unfortunately this is not how last-child works.
    – Salman A
    Dec 26 '18 at 8:59










  • yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
    – Faisal Janjua
    Dec 26 '18 at 10:11



















0














I have solution but this is not native, so I'll not prefer but I'm using until I get proper solution.






function getLastVisibleColumn(){
$('table tr td').removeClass('lastVisibleChild');
$('table tr').each(function(){
$(this).find('td:visible:last').addClass('lastVisibleChild');
});
}
$(window).resize(function(){
getLastVisibleColumn();
});
$(document).ready(function(){
getLastVisibleColumn();
});

.lastVisibleChild {
background: #9F9;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td style="display:none">Text</td>
<td style="display:none">Text</td>
<td style="display:none">Text</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td style="display:none">Text</td>
<td style="display:none">Text</td>
<td style="display:none">Text</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
<td style="display:none">Text</td>
<td style="display:none">Text</td>
<td style="display:none">Text</td>
</tr>
</tbody>
</table>








share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53929677%2fhow-to-detect-last-visible-column-in-responsive-state-of-datatables%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can detect Window resize, and DOM change events using domsubtreemodified and window resize event. You can't do this using pure css, as you can not combine :not and :style selector together






    $(window).resize(function(){
    $('td:visible:last').css('color', 'red');
    });
    $(document).ready(function(){
    $('td:visible:last').css('color', 'red');
    });
    $('table , table td').on("DOMSubtreeModified",function(){
    $('td').css('color', 'black');
    $('td:visible:last').css('color', 'red');
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <td>Home1</td>
    <td>Home2</td>
    <td>Home3</td>
    <td style="display:none">Home4</td>
    <td style="display:none">Home5</td>
    <td style="display:none">Home6</td>
    </tbody>
    </table>








    share|improve this answer



















    • 1




      Unfortunately this is not how last-child works.
      – Salman A
      Dec 26 '18 at 8:59










    • yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
      – Faisal Janjua
      Dec 26 '18 at 10:11
















    0














    You can detect Window resize, and DOM change events using domsubtreemodified and window resize event. You can't do this using pure css, as you can not combine :not and :style selector together






    $(window).resize(function(){
    $('td:visible:last').css('color', 'red');
    });
    $(document).ready(function(){
    $('td:visible:last').css('color', 'red');
    });
    $('table , table td').on("DOMSubtreeModified",function(){
    $('td').css('color', 'black');
    $('td:visible:last').css('color', 'red');
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <td>Home1</td>
    <td>Home2</td>
    <td>Home3</td>
    <td style="display:none">Home4</td>
    <td style="display:none">Home5</td>
    <td style="display:none">Home6</td>
    </tbody>
    </table>








    share|improve this answer



















    • 1




      Unfortunately this is not how last-child works.
      – Salman A
      Dec 26 '18 at 8:59










    • yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
      – Faisal Janjua
      Dec 26 '18 at 10:11














    0












    0








    0






    You can detect Window resize, and DOM change events using domsubtreemodified and window resize event. You can't do this using pure css, as you can not combine :not and :style selector together






    $(window).resize(function(){
    $('td:visible:last').css('color', 'red');
    });
    $(document).ready(function(){
    $('td:visible:last').css('color', 'red');
    });
    $('table , table td').on("DOMSubtreeModified",function(){
    $('td').css('color', 'black');
    $('td:visible:last').css('color', 'red');
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <td>Home1</td>
    <td>Home2</td>
    <td>Home3</td>
    <td style="display:none">Home4</td>
    <td style="display:none">Home5</td>
    <td style="display:none">Home6</td>
    </tbody>
    </table>








    share|improve this answer














    You can detect Window resize, and DOM change events using domsubtreemodified and window resize event. You can't do this using pure css, as you can not combine :not and :style selector together






    $(window).resize(function(){
    $('td:visible:last').css('color', 'red');
    });
    $(document).ready(function(){
    $('td:visible:last').css('color', 'red');
    });
    $('table , table td').on("DOMSubtreeModified",function(){
    $('td').css('color', 'black');
    $('td:visible:last').css('color', 'red');
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <td>Home1</td>
    <td>Home2</td>
    <td>Home3</td>
    <td style="display:none">Home4</td>
    <td style="display:none">Home5</td>
    <td style="display:none">Home6</td>
    </tbody>
    </table>








    $(window).resize(function(){
    $('td:visible:last').css('color', 'red');
    });
    $(document).ready(function(){
    $('td:visible:last').css('color', 'red');
    });
    $('table , table td').on("DOMSubtreeModified",function(){
    $('td').css('color', 'black');
    $('td:visible:last').css('color', 'red');
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <td>Home1</td>
    <td>Home2</td>
    <td>Home3</td>
    <td style="display:none">Home4</td>
    <td style="display:none">Home5</td>
    <td style="display:none">Home6</td>
    </tbody>
    </table>





    $(window).resize(function(){
    $('td:visible:last').css('color', 'red');
    });
    $(document).ready(function(){
    $('td:visible:last').css('color', 'red');
    });
    $('table , table td').on("DOMSubtreeModified",function(){
    $('td').css('color', 'black');
    $('td:visible:last').css('color', 'red');
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <td>Home1</td>
    <td>Home2</td>
    <td>Home3</td>
    <td style="display:none">Home4</td>
    <td style="display:none">Home5</td>
    <td style="display:none">Home6</td>
    </tbody>
    </table>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 26 '18 at 10:21

























    answered Dec 26 '18 at 8:58









    CodeBlaze

    983117




    983117








    • 1




      Unfortunately this is not how last-child works.
      – Salman A
      Dec 26 '18 at 8:59










    • yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
      – Faisal Janjua
      Dec 26 '18 at 10:11














    • 1




      Unfortunately this is not how last-child works.
      – Salman A
      Dec 26 '18 at 8:59










    • yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
      – Faisal Janjua
      Dec 26 '18 at 10:11








    1




    1




    Unfortunately this is not how last-child works.
    – Salman A
    Dec 26 '18 at 8:59




    Unfortunately this is not how last-child works.
    – Salman A
    Dec 26 '18 at 8:59












    yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
    – Faisal Janjua
    Dec 26 '18 at 10:11




    yes it will work but how to detect change event? like it will not work if new column is added/removed in hidden list... also change in screen resolution. so I need change event of responsive (I think responsive.recalc() but dont know how it will run automatically)
    – Faisal Janjua
    Dec 26 '18 at 10:11













    0














    I have solution but this is not native, so I'll not prefer but I'm using until I get proper solution.






    function getLastVisibleColumn(){
    $('table tr td').removeClass('lastVisibleChild');
    $('table tr').each(function(){
    $(this).find('td:visible:last').addClass('lastVisibleChild');
    });
    }
    $(window).resize(function(){
    getLastVisibleColumn();
    });
    $(document).ready(function(){
    getLastVisibleColumn();
    });

    .lastVisibleChild {
    background: #9F9;
    }

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <table>
    <tbody>
    <tr>
    <td>Text</td>
    <td>Text</td>
    <td>Text</td>
    <td style="display:none">Text</td>
    <td style="display:none">Text</td>
    <td style="display:none">Text</td>
    </tr>
    <tr>
    <td>Text</td>
    <td>Text</td>
    <td>Text</td>
    <td style="display:none">Text</td>
    <td style="display:none">Text</td>
    <td style="display:none">Text</td>
    </tr>
    <tr>
    <td>Text</td>
    <td>Text</td>
    <td>Text</td>
    <td style="display:none">Text</td>
    <td style="display:none">Text</td>
    <td style="display:none">Text</td>
    </tr>
    </tbody>
    </table>








    share|improve this answer


























      0














      I have solution but this is not native, so I'll not prefer but I'm using until I get proper solution.






      function getLastVisibleColumn(){
      $('table tr td').removeClass('lastVisibleChild');
      $('table tr').each(function(){
      $(this).find('td:visible:last').addClass('lastVisibleChild');
      });
      }
      $(window).resize(function(){
      getLastVisibleColumn();
      });
      $(document).ready(function(){
      getLastVisibleColumn();
      });

      .lastVisibleChild {
      background: #9F9;
      }

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <table>
      <tbody>
      <tr>
      <td>Text</td>
      <td>Text</td>
      <td>Text</td>
      <td style="display:none">Text</td>
      <td style="display:none">Text</td>
      <td style="display:none">Text</td>
      </tr>
      <tr>
      <td>Text</td>
      <td>Text</td>
      <td>Text</td>
      <td style="display:none">Text</td>
      <td style="display:none">Text</td>
      <td style="display:none">Text</td>
      </tr>
      <tr>
      <td>Text</td>
      <td>Text</td>
      <td>Text</td>
      <td style="display:none">Text</td>
      <td style="display:none">Text</td>
      <td style="display:none">Text</td>
      </tr>
      </tbody>
      </table>








      share|improve this answer
























        0












        0








        0






        I have solution but this is not native, so I'll not prefer but I'm using until I get proper solution.






        function getLastVisibleColumn(){
        $('table tr td').removeClass('lastVisibleChild');
        $('table tr').each(function(){
        $(this).find('td:visible:last').addClass('lastVisibleChild');
        });
        }
        $(window).resize(function(){
        getLastVisibleColumn();
        });
        $(document).ready(function(){
        getLastVisibleColumn();
        });

        .lastVisibleChild {
        background: #9F9;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <table>
        <tbody>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        </tbody>
        </table>








        share|improve this answer












        I have solution but this is not native, so I'll not prefer but I'm using until I get proper solution.






        function getLastVisibleColumn(){
        $('table tr td').removeClass('lastVisibleChild');
        $('table tr').each(function(){
        $(this).find('td:visible:last').addClass('lastVisibleChild');
        });
        }
        $(window).resize(function(){
        getLastVisibleColumn();
        });
        $(document).ready(function(){
        getLastVisibleColumn();
        });

        .lastVisibleChild {
        background: #9F9;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <table>
        <tbody>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        </tbody>
        </table>








        function getLastVisibleColumn(){
        $('table tr td').removeClass('lastVisibleChild');
        $('table tr').each(function(){
        $(this).find('td:visible:last').addClass('lastVisibleChild');
        });
        }
        $(window).resize(function(){
        getLastVisibleColumn();
        });
        $(document).ready(function(){
        getLastVisibleColumn();
        });

        .lastVisibleChild {
        background: #9F9;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <table>
        <tbody>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        </tbody>
        </table>





        function getLastVisibleColumn(){
        $('table tr td').removeClass('lastVisibleChild');
        $('table tr').each(function(){
        $(this).find('td:visible:last').addClass('lastVisibleChild');
        });
        }
        $(window).resize(function(){
        getLastVisibleColumn();
        });
        $(document).ready(function(){
        getLastVisibleColumn();
        });

        .lastVisibleChild {
        background: #9F9;
        }

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <table>
        <tbody>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        <tr>
        <td>Text</td>
        <td>Text</td>
        <td>Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        <td style="display:none">Text</td>
        </tr>
        </tbody>
        </table>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 '18 at 14:56









        Faisal Janjua

        184




        184






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53929677%2fhow-to-detect-last-visible-column-in-responsive-state-of-datatables%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas