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.
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
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.
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.
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
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
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.
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.
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.
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
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.
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.
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
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
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.
If you use jquery, you can use the jquery plug-in tablesort, see the instructions: http://blog.csdn.net/classicb...
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.