Skip to content

napengam/table-cell-resize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Demo

Demo

Resizable Table Columns

This JavaScript function provides a way to make table columns resizable in HTML tables.
The original code was based on the work done by phuocng and can be found here.

How to Use

  1. Include the cellResize.js script in your HTML:

    <script src="cellResize.js"></script>
  2. Call the initResize(tid) function, passing the table's ID as an argument:

    <script>
        const resizableTable = initResize('your-table-id');
    </script>
  3. You can also set a hook function to execute after resizing using setHookAfterResize(aFunc):

    <script>
        resizableTable.setHookAfterResize(() => {
            // Your custom logic after resizing here
        });
    </script>

Dependencies

  • This function requires no additional dependencies or libraries.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Resizable Table Columns Example</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: left;
        }
    </style>
    <script src="resize-table-columns.js"></script>
</head>
<body>
    <table id="myTable">
        <thead>
            <tr>
                <th>Name</th>
                <th>Age</th>
                <th>Country</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>John Doe</td>
                <td>25</td>
                <td>USA</td>
            </tr>
            <!-- ... more rows ... -->
        </tbody>
    </table>

    <script>
        const resizableTable = initResize('myTable');

        resizableTable.setHookAfterResize(() => {
            console.log('Table column resized!');
        });
    </script>
</body>
</html>

Replace 'your-table-id' with the actual ID of your table. Include this script in your HTML and customize the table ID and hook function as needed.

License

This code is provided under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published