Recently, I ran into trouble of a HTML table design problem. I have a CS program and I want to rebuild it into a BS program. This is the UI screen capture.
As you see, it has too many columns. A horizontal scrollbar will appear. How can I improve the user experience?
I tried to combine several columns into one, but it brought some new problems——confusion, not good to filter and sort.
If you have an good example, please show me.
If you need to add multiple columns or rows simultaneously to a table, the best way to do that is via HTML in the RTE Source. In the Source, the table is defined within the <table> HTML tag, each table row is defined with the <tr> HTML tag, and a table data/cell is defined with the <td> HTML tag.
Creating Tables in HTML You can create a table using the <table> element. Inside the <table> element, you can use the <tr> elements to create rows, and to create columns inside a row you can use the <td> elements. You can also define a cell as a header for a group of table cells using the <th> element.
You first declare the table with the <table> markup, and then the rows with the <tr> markup. (table row.) Inside each row, you can declare the data containers <td> . (table data).
After long long time thinking, not perfectly, but I found some workarounds. I post my solutions here for references.
1, Allow horizontal scrollbar for too long columns. This can be done easily by adding a DIV tag wrapping the table like this:
<div style="overflow-x: auto;">
<table class="no-wrap">
<!-- stuff -->
<!-- no-wrap is a AdminLTE style which makes the text in the table do not wrap -->
</table>
</div>
2,Allow the user control which columns be shown. I did this by adding a modal dialog based on Bootstrap. In reducing the displaying column number, you will find it looks better in narrow screen.
This is not hard by writing some JavaScript code and and make it common in your project. Do remember to make good use of the Local Storage technology to save the user's configuration locally and restore the state next time user opening this page. In my solution, my Local Storage key is like this:
my-datatable-hide-col:/business/order:tb-order
my-datatable-hide-col
is fixed, /business/order
is the path, and the tb-order
is the table's id. This Local Storage key's value is like this:
[0, 3, 4]
This means the column 0, column 3 and column 4 is going to be hidden. If the value is not exist or empty, no column will be hidden.
3,Allow the user control the column's order. It's similar to controlling columns' displaying state above.
This also can be done by writing some JavaScript code and make it common.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With