您的位置:首页 > 其它

jq插件 datatable的使用(附上window一些方法)

2017-12-20 15:51 1076 查看

datatable使用

data 为后端传过来的数组值

function initfellTable(data){
datatable = data;
$("#myTable").html("<thead><tr><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th><th>"+$.i18n.prop('')+"</th></tr></thead>");
var TbodyLength =20
// var data = [
//    {
//        "area_id":       "Tiger Nixon",
//        "city_name":   "2",
//        "poorgridnum":     "3,120",
//        "totaldatavolume": "3",
//    },
//    {
//        "area_id":       "Tiger Nixon",
//        "city_name":   "222",
//        "poorgridnum":     "5,300",
//        "totaldatavolume": "333"
//    }
//    ];
var options = {
"pagingType": "input",
"oLanguage": {
"sZeroRecords":$.i18n.prop(''),
"oPaginate": {
"sFirst": $.i18n.prop(''),
"sPrevious": $.i18n.prop(''),
"sNext": $.i18n.prop(''),
"sLast": $.i18n.prop('')
}
},
"order": [],
"ordering":true,
// "retrieve": true,
"destroy": true,
"searching": true,
"bFilter": false,
"sDom": '<"H"lr>t<"F"ip>',
"bDestory": true,
"bAutoWidth": false,
"bLengthChange": false,
"displayLength": 10,
"bSort": true,
"scrollX": true,
"bPaginate": true,
"columnDefs": [{
    'targets' : [0,1,7],    //除第六,第七两列外,都默认不排序
    'orderable' : false
    },
{
"render": function (data, type, row, rowcol) {
return '<img class="imgdetail" src="img/map/r2_c2.png"/>';
}, "targets": [7]
},
{
"render": function (data, type, row, rowcol) {
return '<span title="'+data+'">'+data+'</span>';
}, "targets": [0]
}

]
}
options.data = data
//data里面没后端传过来的列名
options.columns= [
{ data: 'area_id' },
{ data: 'city_name' },
{ data: 'pqfeelgridnum' },
{ data: 'poorcoveragegridnum' },
{ data: 'exceptionusernum' },
{ data: 'exceptionvalueusernum' },
{ data: 'totaldatavolume' },

];
$("#myTable").dataTable(options);

}


window一些方法

1.window.open()

打开一个新的窗口

例子:导出功能

$.ajax({
method: "post",
url: '',
async:false,
data:data,
success: function(data){
window.open(data.result)
showModalBox();
}
});


2.window.location.href

完整的url

url.split(“//”)[1].split(“.”)[0]

split:按指定字符分割字符串

3.window.location.search/location.search

获取url ?后面的部分

function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
if (url.indexOf("day")>-1) {

var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
}else{

}
return theRequest;

}


unescape() :可对通过 escape() 编码的字符串进行解码。

该函数的工作原理是这样的:通过找到形式为 %xx 和 %uxxxx 的字符序列(x 表示十六进制的数字),用 Unicode 字符 \u00xx 和 \uxxxx 替换这样的字符序列进行解码。

ECMAScript v3 已从标准中删除了 unescape() 函数,并反对使用它,因此应该用 decodeURI() 和 decodeURIComponent() 取而代之。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: