Sortable Table Columns with Javascript

Поделиться
HTML-код
  • Опубликовано: 11 янв 2025

Комментарии • 20

  • @jeff-creations
    @jeff-creations 2 года назад

    Thanks for the super straight forward video Dennis, I learned a bunch. I'm going to follow along for the next few videos in the series as well! I don't really know jQuery and am really trying to learn Vanilla Javascript first. I spent some time trying to convert the jQuery you used to Javascript. I had issues getting the icons to change so I went down a different road with the icons. That said I am going to post what I have so far for those viewers that want the Javascript approach.

  • @junyuwang536
    @junyuwang536 2 года назад

    Dennis you saved the last piece missing from my hw you're god to me now

  • @isaacjpg
    @isaacjpg 4 года назад

    Seeing the whole series ... thank you for the video

  • @srikannandairy
    @srikannandairy 4 года назад +3

    Your tutorials are great in terms of content, clarity and pace. I am a Django developer. I have doubt whether we can check the user group in js code.

  • @naishadhchawra7508
    @naishadhchawra7508 3 года назад

    thanks man . Finally got this .

  • @rexorgutierrez4063
    @rexorgutierrez4063 3 года назад +4

    How about when the data is came from the database how it should connect? please answer me

  • @ketz555
    @ketz555 3 года назад +5

    11:20 The date sort doesn't work

    • @EIGatito
      @EIGatito 2 года назад +1

      What the solution of it? Plzzzz

    • @marygracetecson7148
      @marygracetecson7148 Год назад +1

      @@EIGatito date should be in yyyy/mm/dd format

  • @tariqshaikh459
    @tariqshaikh459 3 года назад

    I had fetched my data from an API and displayed it on the browser if I want to sort data on that values what changes do I need to make in place of "myArray". Thank You

    • @saiganeshn8588
      @saiganeshn8588 3 года назад

      Did you figure that out bro I am also having that doubt

  • @daedalusrasmus3278
    @daedalusrasmus3278 4 года назад

    There's problems with the case of the letters. Uppercase letters have precedence over lowercase ones...

  • @santiagowhite5467
    @santiagowhite5467 3 года назад

    Why do I have a problem with the click function? It does not trigger the console log

  • @GavishSethi
    @GavishSethi 3 года назад +1

    good but little more explanation would have been better

  • @Modafinil
    @Modafinil 4 года назад +1

    How about sorting according to the date column? I think it does not work. I added a section which does the same than your code but converts a[column] and b[column] to Date objects. It seems to work after that but I'm so inexperienced with javascript that it's better not to declare the problem as solved.
    Here is what I did:
    if(column == 'birthdate')
    {
    if(order == 'desc'){
    $(this).data('order', "asc")
    myArray = myArray.sort((a,b) => new Date(a[column]) > new Date(b[column]) ? 1 : -1)
    text += '▼'
    }else{
    $(this).data('order', "desc")
    myArray = myArray.sort((a,b) => new Date(a[column]) < new Date(b[column]) ? 1 : -1)
    text += '▲'
    }
    }
    else
    if(order == 'desc'){
    $(this).data('order', "asc")
    myArray = myArray.sort((a,b) => a[column] > b[column] ? 1 : -1)
    text += '▼'
    }else{
    $(this).data('order', "desc")
    myArray = myArray.sort((a,b) => a[column] < b[column] ? 1 : -1)
    text += '▲'
    }
    However it would also be nice if one would be able to leave only the sorting triangle to the column header which is currently sorted and remove the triangles from those column headers. This could avoid users confusion but it still would be nice to indicate somehow that the column headers are providing sorting for table items. For example, Windows Explorer is providing that kind of behavior.

  • @cengiz-ilhan
    @cengiz-ilhan 3 года назад

    thanks

  • @Modafinil
    @Modafinil 4 года назад

    What if the stuff of one column you want to sort is in Item to be sorted? Sorting should be done according to the text content. Not according to a DOM element.

    • @Modafinil
      @Modafinil 4 года назад

      tableData = tableData.sort((a, b) => $("").html(a[column]).text() > $("").html(b[column]).text() ? 1 : -1);

  • @UsmanJawad-hn6dx
    @UsmanJawad-hn6dx 2 месяца назад

    thanks