Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery数据表排序图像位置_Jquery_Jquery Ui_Jquery Datatables - Fatal编程技术网

JQuery数据表排序图像位置

JQuery数据表排序图像位置,jquery,jquery-ui,jquery-datatables,Jquery,Jquery Ui,Jquery Datatables,我正在使用jQueryDataTables,并希望移动排序图像,即排序箭头图像应为列标题右侧的10px。通过将下面的css属性更改为左、右或中,似乎对我不起作用。我希望图像(排序图像)是cloumn头名称右侧的10px。假设列头是帐户经理名称 .sorting_asc { background: url('images/sort_asc.png') no-repeat center center; color:#000000; text-align:left;

我正在使用jQueryDataTables,并希望移动排序图像,即排序箭头图像应为列标题右侧的10px。通过将下面的css属性更改为左、右或中,似乎对我不起作用。我希望图像(排序图像)是cloumn头名称右侧的10px。假设列头是帐户经理名称

.sorting_asc { 
 background: url('images/sort_asc.png') no-repeat center center;    
   color:#000000;  
text-align:left;       
 } 
请帮忙


谢谢

您需要将父div设置为相对或绝对。然后将图标div也设置为绝对值。然后,您可以使用left和top在该元素中定位图标

定位可能令人困惑。我喜欢这段视频,它能很好地解释定位以及它们如何相互作用


您需要将父div设置为相对或绝对。然后将图标div也设置为绝对值。然后,您可以使用left和top在该元素中定位图标

定位可能令人困惑。我喜欢这段视频,它能很好地解释定位以及它们如何相互作用

**//您可以使用以下解决方法来实现相同的目标**
$('tableId').Datatable({
initComplete:函数(设置,json){
变量span排序=“”;
$('tableId'+“thead th”)。每个(函数(i,th){
var cls=$(th).attr('class');
//只有可排序列应使用具有相应背景图标的新可排序范围进行更新
如果(cls==‘排序’| | cls==‘排序| asc’| | cls==‘排序|描述’){
$(th).html($(th).html()+span排序);
}
});
},
});
//删除datatable css中th的背景图像
table.dataTable thead.排序{
背景图像:无;
}
table.dataTable thead.sorting\u asc{
背景图像:无;
}
table.dataTable thead.sorting\u desc{
背景图像:无;
}
//添加新的css属性以显示动态创建范围的排序图像
table.dataTable thead.sorting span.arrow-hack{
背景图像:url(“../datatables/images/sort_both.png”);
背景位置:13px 17px;
左边距:10px;
}
table.dataTable thead.sorting\u asc span.arrow-hack{
背景图像:url(“../datatables/images/sort_asc.png”);
背景位置:13px 17px;
左边距:10px;
}
table.dataTable thead.sorting_desc span.arrow-hack{
背景图像:url(“../datatables/images/sort_desc.png”);
背景位置:13px 17px;
左边距:10px;
}
**//您可以使用以下解决方法来实现相同的目标**
$('tableId').Datatable({
initComplete:函数(设置,json){
变量span排序=“”;
$('tableId'+“thead th”)。每个(函数(i,th){
var cls=$(th).attr('class');
//只有可排序列应使用具有相应背景图标的新可排序范围进行更新
如果(cls==‘排序’| | cls==‘排序| asc’| | cls==‘排序|描述’){
$(th).html($(th).html()+span排序);
}
});
},
});
//删除datatable css中th的背景图像
table.dataTable thead.排序{
背景图像:无;
}
table.dataTable thead.sorting\u asc{
背景图像:无;
}
table.dataTable thead.sorting\u desc{
背景图像:无;
}
//添加新的css属性以显示动态创建范围的排序图像
table.dataTable thead.sorting span.arrow-hack{
背景图像:url(“../datatables/images/sort_both.png”);
背景位置:13px 17px;
左边距:10px;
}
table.dataTable thead.sorting\u asc span.arrow-hack{
背景图像:url(“../datatables/images/sort_asc.png”);
背景位置:13px 17px;
左边距:10px;
}
table.dataTable thead.sorting_desc span.arrow-hack{
背景图像:url(“../datatables/images/sort_desc.png”);
背景位置:13px 17px;
左边距:10px;

}
也许添加一个JSFIDLE来展示您的示例将有助于清晰地描述问题也许添加一个JSFIDLE来展示您的示例将有助于清晰地描述问题