Column width with colResizable plugin

前端 未结 1 1162
温柔的废话
温柔的废话 2021-01-18 15:48

colResizable appears to be a great plugin for adjustable column widths.

Unfortunately, it removes the widths which were set originally. I was using whitespace:

1条回答
  •  耶瑟儿~
    2021-01-18 15:59

    After studying the source from github, I found a better way.

    The table's layout is changed first when the table is assigned the SIGNATURE class which includes table-layout: fixed; Just before that, I'm pushing the original column widths into a new array. This array is passed to the createGrips function.

    /* init function */
    // ...
    
    var originalColumnWidths = new Array();
    $.each($('th', t), function () {
        originalColumnWidths.push($(this).width());
    });
    
    // t.addClass(SIGNATURE) ...
    
    createGrips(t, originalColumnWidths);
    

    When looping through the columns in the createGrips function, I'm assigning the value from the array to the new jQuery wrapped column object instead of the current column width.

    // Change the signature
    var createGrips = function (t, originalColumnWidths) {
    // ...
    
    // Replace that line
    c.w = c.width();
    // with the following
    c.w = originalColumnWidths[i];
    

    That works for me perfectly. Hope it can help someone!

    0 讨论(0)
提交回复
热议问题