https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • g

    gorgeous-ghost-95789

    03/07/2023, 6:58 PM
    Ooof, I feel for you, @rapid-umbrella-80895. Business requirements include some crazy things, so I get that you may just have to build it this way. But having to build (or even scroll through) 100 tables on a single page sounds like a bad time. This sounds like a great use case for some tabs, or a drop down box in the navigation somwhere. I'm going to bet that htmx will work as well as any other front-end JS library... and maybe better because you're using the browser's parser written in C++ (or Rust) instead of a bolt-on written in Javascript. Still, those results may not be great. Tables are especially expensive because they require some complicated layout calculations. So, do your best to limit the information sent over the wire, and the number of DOM nodes that have to be rendered on every page -- even down to renegotiating the size of this one page with whoever is the business owner / designer.
  • t

    tall-dinner-62086

    03/07/2023, 10:32 PM
    The way you're describing that sounds like it would be faster to just refresh the whole thing instead of cherry-picking the 3/4 tables for update. Replacing a full section will 4 tables is gonna be faster than refreshing 3 separate tables
  • r

    rapid-umbrella-80895

    03/08/2023, 12:12 AM
    Thank you! So the best thing I can do is to replace the whole that includes all the tables, I guess. 👍 In theory, would skipping some tables with django template variables improve the speed? Something like: {% if htmx_update == False %} // every 4th html table, I do not want to update// {% endif %} My assumption would be, that it would take a tiny bit longer time for django to generate the template, by evaluating this extra conditional logic but then htmx would take less time to swap the shorter html content this way. Is this a wrong idea?
  • r

    refined-waiter-90422

    03/08/2023, 5:41 AM
    the jinja / django template logic is going to be relatively fast, especially with python 3.11+. So yeah, probably a good place to start. Wins here are going to be very implementation specific depending on where the actual bottlenecks are- we can only provide very surface level ideas.
  • e

    enough-petabyte-50314

    03/08/2023, 5:43 AM
    is it possible to narrow the scope of what changes to just the ``s that are in view? seems highly unlikely that the page needs 80 tables all kept up to date. how could anyone view that much data even if you did manage to update it in a good time?
  • b

    billions-solstice-65074

    03/08/2023, 5:52 AM
    I have a table with rows of data. I have a search input element to filter the rows (filtering is done on server side). The rows also have action buttons (freeze, delete). When a user clicks Freeze the row has to go to the top of the table. My current approach is for the server handler for the freeze button to send the whole table with the rows in the correct order. The handler function for freeze can send all the rows but it won't know the search term to apply the filtering.
  • b

    billions-solstice-65074

    03/08/2023, 5:52 AM
    How can I preserve the filtering while still reordering the rows when a user presses the freeze button on a row?
  • e

    enough-petabyte-50314

    03/08/2023, 6:21 AM
    a couple different thoughts come to mind 1. use client-side js to "freeze" the rows instead 2. or include the filter parameter in the "freeze" requests as well 3. or use a cookie to track frozen rows, or a cookie to track the filter
  • f

    freezing-waitress-26396

    03/08/2023, 8:52 AM
    Cookies bring in the issue of multiple tabs of the same site not working as you would want it, but the server cannot access a local storage, hm
  • f

    freezing-waitress-26396

    03/08/2023, 8:54 AM
    oh right,
    sessionStorage
    exists
  • b

    billions-solstice-65074

    03/08/2023, 3:54 PM
    The filter param belongs to the element which is outside the of the table. I'm not sure how I can access the value of the filter param to pass into the freeze request.
  • h

    happy-knife-63802

    03/08/2023, 5:16 PM
    for the sortable users - i have an htmx.onLoad trigger initialising every .sortable element as part of my base template, and this works as expected when hitting a url directly. however, when i swap new content into the body (boosted - so the whole base template is being sent over including the script tags with the sortable init), the swapped in content doesnt work with sortable. do i need to init them again? if so whats the best way to do this with boosted content?
  • h

    happy-knife-63802

    03/08/2023, 7:03 PM
    with some further testing, i can get around this by moving away from using boost (so instead of a tags, using buttons, then specifying hx-select/hx-target and swapping the outerHTML)
  • h

    happy-knife-63802

    03/08/2023, 7:03 PM
    which is annoying because its a lot more code for more or less the same functionality as using boost
  • h

    happy-knife-63802

    03/08/2023, 7:03 PM
    so.. any ideas?
  • l

    late-king-98305

    03/08/2023, 7:09 PM
    This sounds like it's similar to an issue I was having; check out
    htmx:afterSwap
    for initializing your new stuff. This is what I wrote up about my page-level vs. htmx init findings: https://bitbadger.solutions/blog/2023/page-level-javascript-initialization-with-htmx.html
  • h

    happy-knife-63802

    03/08/2023, 7:09 PM
    thanks, i will take a look
  • l

    late-king-98305

    03/08/2023, 7:11 PM
    Although, in reading that over now, it looks like I wrote up
    htmx:afterSwap
    but the code actually uses
    htmx:afterSettle
    . Let me know what you find - I may need to edit my post!
  • h

    happy-knife-63802

    03/08/2023, 7:12 PM
    haha i was just about to mention that to you!
  • l

    late-king-98305

    03/08/2023, 7:15 PM
    I think the elements should be able to be addressed by the time
    htmx:afterSwap
    fires; I'm trying to remember why I ended up using
    htmx:afterSettle
    , but that code was a copy/paste from the project where I used it.
  • h

    happy-knife-63802

    03/08/2023, 7:15 PM
    ive jsut tried both actually and still not working - but youve given me a few ideas
  • l

    late-king-98305

    03/08/2023, 7:19 PM
    You might try running the init in the browser console once the content is there. If it works, there's likely something in the timing/events that's not right. If it doesn't work there, maybe there's something in the content that's being returned that isn't matching what your code is expecting.
  • h

    happy-knife-63802

    03/08/2023, 7:20 PM
    ive tried running the init in the browser - it works.. so yeah i guess more investigating needed.. or drop boost
  • h

    happy-knife-63802

    03/08/2023, 7:21 PM
    afterSettle was a good call but it still isnt playing with sortable this way, very confused given that it works fine with hx-get
  • l

    late-king-98305

    03/08/2023, 7:22 PM
    Are you sure afterSettle is being called? Also, if you want it to run after every settle, you'd want to take the "once" stuff off the listener.
  • h

    happy-knife-63802

    03/08/2023, 7:23 PM
    theres no once on the listener, and yes its being called - console.log says so
  • l

    late-king-98305

    03/08/2023, 7:24 PM
    Well, shucks - that's about all I can think of. There are others here who have more experience in that than I do; maybe they'll read this exchange and have some better ideas.
  • h

    happy-knife-63802

    03/08/2023, 7:24 PM
    appreciate it 😄
  • m

    magnificent-camera-86904

    03/09/2023, 6:39 AM
    How can I get a
    textarea
    to trigger an htmx request when the user presses enter? This is what I have so far:
    Copy code
    html
    <form id="chatbox-submit">
      {% csrf_token %}
      <textarea id="question-text-area" hx-trigger="keyup"></textarea>
    </form>
    I tried
    hx-trigger="enter"
    and
    Enter
    but neither worked. I don't see any examples of using keys in the HTMX docs https://htmx.org/docs/#triggers Bonus, It would be nice if it only submitted when the user presses Enter, but not Shift+Enter. This is how I know to do it in JS
    Copy code
    js
    const node = chatBox.querySelector("textarea");
    
    node.addEventListener("keyup", ({ key, shiftKey }) => {
      if (key === "Enter" && !shiftKey) {
        // Do things
      }
    });
    I asked a related question awhile back and I solved it because it seemed like the browser knew that hitting enter was 'submit' ...but that was when I was using an input element. Things broke when I started using
    textarea
    https://discord.com/channels/725789699527933952/725789747212976259/1079989023482855494
  • r

    ripe-action-67367

    03/09/2023, 6:59 AM
    See trigger filters https://htmx.org/docs/#trigger-filters https://htmx.org/attributes/hx-trigger/
1...106110621063...1146Latest