search

Home  >  Q&A  >  body text

javascript - ajax sorting problem

This is the form I loop out by reading the database

Now I want to sort by clicking name, gender, family, how should I write this using ajax?

天蓬老师天蓬老师2834 days ago932

reply all(9)I'll reply

  • 三叔

    三叔2017-06-13 09:23:54

    If the number of data items is particularly large, it is strongly recommended that you use the dataTables plug-in. This plug-in is quite complete for displaying data in tables. Issues like sorting are minor issues.

    reply
    0
  • 为情所困

    为情所困2017-06-13 09:23:54

    You have so many problems with one project, is this an internship? This is a graduation project...
    1. To get sorted data with ajax, at least two more fields are needed, one is the field that needs to be sorted, and one is desc or asc
    2. Since the sorting is not set at the beginning, the default sorting is required , generally id desc.
    3. To avoid system-level query errors caused by problems with the passed sorting parameters, you must verify the parameters, verify whether the field exists in the table, or whether the field is set to be sorted. Use the ternary operator to set whether the sorting is from small to large or large to small

    The front end binds a click event to th of each thead, and th must have two attributes, the attribute field and the sorting method

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-13 09:23:54

    ajax just requests the backend data, passes the sorting method you want to the backend as parameters, and then the backend queries and returns the data for display.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-13 09:23:54

    This has nothing to do with ajax, the sorting results are generated in the background.

    You can submit the field name + sorting method to the background through ajax, and the background will output the sorted json, and then update it to the dom.

    The front desk can also sort the current table by traversing the current table.

    reply
    0
  • 黄舟

    黄舟2017-06-13 09:23:54

    dataTables This plug-in can do it. You can go to the official website to see the examples. The operation is also very convenient and the function is very powerful

    reply
    0
  • 巴扎黑

    巴扎黑2017-06-13 09:23:54

    One solution is to use mvvm frameworks such as vue and react, and the other is to return to the client after sorting on the server by adjusting different interfaces. Recommend the first option

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-13 09:23:54

    For local sorting, you just use the algorithm to compare the obtained data. Reference: /a/11... The second half.
    Otherwise, just like Datatables, just give instructions and get the data in the background.
    However, I guess you want client-side sorting. PS: I have used the Datatables plug-in before. There are a lot of APIs to implement your functions. I feel that it is overkill and may take more time. Datatables has a Chinese website, but the introduction is not very detailed.

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-13 09:23:54

    If you use jquery, you can use the jquery plug-in tablesort, see the instructions: http://blog.csdn.net/classicb...

    reply
    0
  • ringa_lee

    ringa_lee2017-06-13 09:23:54

    If you feel that there is no paging, just use js's .sort(). Delete the table and regenerate it every time you click it. If you want to be more efficient, it is better to find an html template library, such as doT.js.

    reply
    0
  • Cancelreply