Jquery Datatable 到响应式数据表

2023-12-13

我是数据表新手,从未创建过响应式数据表。所以我可能需要很多帮助。

Here is link用于可编辑的 JQuery 数据表。我想将其创建为响应式。我做的第一件事是删除了它的容器宽度,现在它的大小调整为平板电脑大小的屏幕,看起来不错。

#fw_container {
    margin: 0 auto;
    max-width: 90%;
    padding-top: 2em;
}
.full_width {
    width: 90%;
}

但在下面的屏幕尺寸上,表格却乱七八糟。

我希望数据表的工作方式如下this.

我无法向您提供我实际实施的网站链接,因为它位于网站管理面板中。

任何想法/有用的链接或方向都会对我有帮助。多谢!


在响应式设计中,大多数技巧都是通过百分比值完成的,直到某个点,然后我们开始使用 @media 查询。

对于您的示例,仅使用 th 和 td 标签的百分比,我相信您可以管理它,但如果它小于 40em,则完全不同的 CSS 会进行控制,如下所示;

//when width less than 40em you can also use px
@media (max-width: 40em)
{
   // show every item as a line
   .movie-list td, .movie-list th {
   width: 100%;
   -webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   box-sizing: border-box;
   float: left;
   clear: left;
  }
    //for th and .titles display them as a big bold title with different background color
    .movie-list tbody th, .movie-list tbody td.title {
    display: block;
    font-size: 1.2em;
    line-height: 110%;
    padding: .5em .5em;
    background-color: #fff;
    color: #77bbff;
    -moz-box-shadow: 0 1px 6px rgba(0,0,0,.1);
    -webkit-box-shadow: 0 1px 6px rgba(0,0,0,.1);
    box-shadow: 0 1px 6px rgba(0,0,0,.1);
    }

    //for th only this is only for margin to override previous css
    .movie-list tbody th {
       margin-top: 0;
       text-align: left;
     }
}

希望这能有所帮助,这只是一个开始;

这是你的鱼伙伴:) 只需使用开发人员工具栏并在 h2 Live Examples 标签下添加代码即可;

<style>
// check if it is a small device ipad iphone android etc.
// google for example 'css  media queries for mobile"
@media (max-width: 40em) {
  // just did something to display second row use your skills
  table#example tr.even
  {
     border: 2px solid red;
  }  
// exactly the same with other one to display td as rows
// with css selector you can hide first one display 2nd one like a title etc
table#example tr td 
  {
  background-color:white;
     width: 90%;
   -webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   box-sizing: border-box;
   float: left;
   clear: left;
  }  
  // remove the thead as we dont need it
  // you should do similar to the footer as well
  table#example thead
  {
     display:none;
  }  
  // hide unwanted pagination elements
  table#example ~ div.fg-toolbar div#example_info, 
    table#example ~ div.fg-toolbar div a
  {
  display:none;
  }
  // and only display next and prev
  // it s not what I actually wanted to make it more tab able make it bigger and try to cover half of the row.  
  table#example ~ div.fg-toolbar div a#example_previous,
  table#example ~ div.fg-toolbar div a#example_next
  {
  display:inline-block;
  width:46% !important;

  }
}

</style>

据我所知,编辑和添加内容正在工作,因为这完全是 css,只是你必须深入挖掘。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jquery Datatable 到响应式数据表 的相关文章