使用jQuery插件使表列可调整大小

编程入门 行业动态 更新时间:2024-10-28 22:29:21
本文介绍了使用jQuery插件使表列可调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用DataTables和 jquery-resizable-columns 来创建具有可调整大小的列的表。这是示例。

I use DataTables and jquery-resizable-columns to create table with resizable columns. Here is example.

我试过在DataTables的基本ReactJS应用程序中使用jquery-resizable-columns插件。我在 componentDidMount 中添加了 resizableColumns 函数,但它不起作用。

I tried to use jquery-resizable-columns plugin in basic ReactJS application with DataTables. I added resizableColumns function in componentDidMount, but it doesn't work.

我在ReactJS,有人可以向我解释为什么它不起作用吗?

I am in ReactJS, can anybody explain to me why it doesn't work?

jsfiddle

jsx script

/** @jsx React.DOM */ var TodoApp = React.createClass({ getInitialState: function() { return {items: [], text: ''}; }, render: function() { return ( <div> <h3>React + jQuery.DataTable</h3> <LopMonHoc /> </div> ); } }); var LopMonHoc = React.createClass({ getInitialState: function(){ return {data: []} }, componentDidMount: function(){ var self = this; $('#mytable').DataTable({ "bAutoWidth": false, "bDestroy": true, "fnDrawCallback": function() { self.forceUpdate(); }, }); $("#mytable").resizableColumns(); }, componentDidUpdate: function(){ $('#mytable').DataTable({ "bAutoWidth": false, "bDestroy": true, }); }, render: function(){ var x = []; x.push( <tr><td>zaxs</td><td>hello</td><td>xzc</td></tr> ) x.push( <tr><td>hello</td><td>wef</td><td>qw</td></tr> ) x.push( <tr><td>wefwe</td><td>fgn</td><td>asc</td></tr> ) return ( <div className="table-responsive"> <h4>Hello</h4> <table className="table table-bordered" id="mytable"> <thead> <tr className="success"> <td>col1</td> <td>col2</td> <td>col3</td> </tr> </thead> <tbody> {x} </tbody> </table> </div> ) } }); React.render(<TodoApp />, document.body);

推荐答案

关于ReactJS和整个节点生态系统的好处是那个人在那里完成了工作并变成了一个插件/模块。以下是对您有用的内容: colresizable 。关于这一点的好处是,您不必管理每个组件的放置位置,它可以满足您的需求和更多...

The nice thing about ReactJS and the whole node ecosystem is that someone else out there has done the work and turned into a plugin/module. Here is something that will be of use to you: colresizable. The nice thing about this is that you won't have to manage where to put things for each component and it does what you want and more...

您需要将此添加到 componentDidUpdate 方法的末尾...

You need to add this to the end of your componentDidUpdate method...

$(function(){$("#mytable").colResizable();});

您有:

... componentDidMount: function(){ var self = this; $('#mytable').DataTable({ "bAutoWidth": false, "bDestroy": true, "fnDrawCallback": function() { self.forceUpdate(); }, }); $("#mytable").colResizable(); }, componentDidUpdate: function(){ $('#mytable').DataTable({ "bAutoWidth": false, "bDestroy": true, }); }, ...

您需要更改为:

... componentDidMount: function(){ var self = this; $('#mytable').DataTable({ "bAutoWidth": false, "bDestroy": true, "fnDrawCallback": function() { self.forceUpdate(); }, }); }, componentDidUpdate: function(){ $('#mytable').DataTable({ "bAutoWidth": false, "bDestroy": true, }); $(function(){$("#mytable").colResizable();}); }, ...

我刚刚在jsfiddle链接上测试过你提供并能够调整列的大小。

I just tested it on jsfiddle link you provided and was able to resize the columns.

更多推荐

使用jQuery插件使表列可调整大小

本文发布于:2023-11-11 13:35:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   可调整   大小   jQuery   使表列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!