在jQuery中向Datatable添加更多下拉或HTML元素 [英] Adding more drop down or html elements to Datatable in Jquery

查看:474
本文介绍了在jQuery中向Datatable添加更多下拉或HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在默认值之后向数据表添加更多下拉列表或其他html元素

Is it possible to add more drop down or other html elements to the Datatable after the default

显示 5记录

我想在默认值和默认提供的搜索栏之间向DataTable添加更多下拉列表。

I want to add more drop down to my DataTable between the Default one and the Search Bar which is provided by default.

我已经通过sDom,但是我无法理解其语法。

I have gone through sDom but I am not able to understand the syntax.

预先感谢。

推荐答案

您可以通过以下方式在长度菜单和过滤器框之间插入元素< div>

You can insert an element <div> between the length menu and the filter box this way :

var table = $('#example').DataTable({
   dom : 'l<"#add">frtip'
}) 

'lfrtip' 是默认的 dom 字符串,因此您基本上只需添加< div id =#add> 到现有布局。建议设置 #add 的样式,尤其是将 display 类型设置为 inline-block ,因此不会破坏以下元素:

'lfrtip' is the default dom string, so you basically just add an <div id="#add"> to the existing layout. It is adviceable to style #add, especially setting the display type to inline-block so it not break the elements down under :

#add {
  display: inline-block;
  padding-left: 30px;
  float: left;
}

现在您可以添加< select> (或其他)到 #add 元素的简单jQuery方式:

Now you can add <select>'s (or whatever) to the #add element the plain jQuery way :

//insert a label
$('<label/>').text('my dropdown').appendTo('#add')

//insert the select and some options
$select = $('<select/>').appendTo('#add')
$('<option/>').val('1').text('option #1').appendTo($select);
$('<option/>').val('2').text('option #2').appendTo($select);
$('<option/>').val('3').text('option #3').appendTo($select);

demo-> http://jsfiddle.net/ahqbf35w/

demo -> http://jsfiddle.net/ahqbf35w/

这篇关于在jQuery中向Datatable添加更多下拉或HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆