简体   繁体   中英

How to re-size rows and columns of a html table using jquery?

I am using both colResizable(for adjusting column) and Resizable function(for adjusting row) it is working good in mozilla firefox but not working in chrome

For column we are using the following link - http://quocity.com/colresizable/
For row we are using following jquery function - $("#tblResize2 tr").resizable();

note : on the above code we tried using td (instead of tr) to resize columns it is not working after the final impact.

$("#MatrixTable").colResizable({
                onResize: onSampleResized
            });

            $("#MatrixTable tr").resizable();
            $("#MatrixTable td").resizable();

Whole function

 var onSampleResized = function (e) {

  var columns = $(e.currentTarget).find("td");
            var rows = $(e.currentTarget).find("tr");
            var full_msg;
            var row_msg;

        `columns.each(function () { full_msg += $(this).attr('id') + "_" +` $(this).width() + "_" + $(this).height() + ";"; })
        rows.each(function () { row_msg += $(this).attr('id') + "_" + $(this).width() + "_" + $(this).height() + ";"; })
        document.getElementById("hf_data").value = full_msg
        document.getElementById("hf_rowdata").value = row_msg;

    };

Thanks in advance

I have a working sample here: JSFiddle

I think you have a few issues with the function. There were several missing ; that chrome may have not liked, try the following.

Full Javascript:

$(function () {
        var onSampleResized = function (e) {
        var columns = $(e.currentTarget).find("th");
        var rows = $(e.currentTarget).find("tr");
        var full_msg = "";
        var row_msg = "";
        columns.each(function () {
            full_msg += $(this).attr('id') + ":" + $(this).width() + "x" + $(this).height() + ";\n";
        });
        rows.each(function () {
            row_msg += $(this).attr('id') + ":" + $(this).width() + "x" + $(this).height() + ";\n";
        });
        document.getElementById("hf_data").value = full_msg;
        document.getElementById("hf_rowdata").value = row_msg;
    };

    $("#MatrixTable").colResizable({
        onResize: onSampleResized
    });

    $("#MatrixTable tr").resizable();
    $("#MatrixTable td").resizable();



});

Check out the resizable function of the jQuery UI library. You shouldn't even need colResizable. It works with everything. Comes with JS and CSS for resizable items.

http://jqueryui.com/resizable/

Got it working in JSFiddle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM