我正在使用jQuery数据表来管理表。在这里我需要在表格上添加一个div,而不是像下面的
那样在分页div上添加<div class="class-name"> <table></table> </div> <div class="dataTables_paginate paging_simple_numbers"></div>
有人可以帮助我吗?
答案 0 :(得分:3)
问题是陈旧的,但今天我遇到了同样的问题。所以这是&#34;官方&#34;溶液:
在初始化DataTable的JavaScript部分中,您可以像这样修改生成的DOM:
#define NUMMONTHS 12
#define NUMYEARS 5
#include <stdio.h>
// function prototypes
void inputdata();
void printdata();
// Global variables
// These are available to all functions
float Raindata[NUMYEARS][NUMMONTHS];
char years[NUMYEARS][5] = {
"2011", "2012", "2013",
"2014", "2015"
};
char months[NUMMONTHS][12] = {
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec"
};
int main() {
char enterData = 'y';
printf("Do you want to input Precipatation data? (y for yes)\n");
scanf("%c", & enterData);
if (enterData == 'y') {
// Call Function to Input data
inputdata();
// Call Function to display data
printdata();
} else {
printf("No data was input at this time\n");
}
printf("Please try the Precipitation program again. \n");
return 0;
}
// function to inputdata
void inputdata() {
/* variable definition: */
float Rain = 1.0;
float total = 0.0;
// Input Data
for (int year = 0; year < NUMYEARS; year++) {
for (int month = 0; month < NUMMONTHS; month++) {
printf("Enter rain for %d, %d:\n", year + 1, month + 1);
scanf("%f", & Rain);
Raindata[year][month] = Rain;
total = total + Rain;
}
printf("Total rainfall: %.2f\t\n", total);
}
}
// Function to printdata
void printdata() {
// Print data
printf("year\t month\t rain\n");
for (int year = 0; year < NUMYEARS; year++) {
for (int month = 0; month < NUMMONTHS; month++) {
printf("%s\t %s\t %5.2f\n", years[year], months[month], Raindata[year][month]);
}
}
}
其中
$('table').DataTable( {
...,
dom: '<"class-name"t>p'
});
转换为<"class-name"
<div class="class-name">
已替换为表格(t
)<table>...</table>
将div关闭为>
</div>
呈现分页元素DataTables文档解释了可用选项: https://datatables.net/examples/basic_init/dom.html
答案 1 :(得分:2)
你可以使用wrap功能:
$('table').wrap('<div class="class-name"></div>');
答案 2 :(得分:1)
您的表格是否有唯一的ID或类?因为那样,你可以简单地使用jQuery函数wrap()。