Commit 8dba54e7 authored by ibuler's avatar ibuler

[Update] 优化table页数

parent 2ef487a9
...@@ -135,7 +135,8 @@ function initAssetModalTable() { ...@@ -135,7 +135,8 @@ function initAssetModalTable() {
], ],
lengthMenu: [[10, 25, 50], [10, 25, 50]], lengthMenu: [[10, 25, 50], [10, 25, 50]],
pageLength: 10, pageLength: 10,
select_style: assetModalOption.selectStyle select_style: assetModalOption.selectStyle,
paging_numbers_length: 3
}; };
assetModalTable = jumpserver.initServerSideDataTable(options); assetModalTable = jumpserver.initServerSideDataTable(options);
if (assetModalOption.onModalTableDone) { if (assetModalOption.onModalTableDone) {
......
...@@ -386,6 +386,10 @@ $(document).ready(function(){ ...@@ -386,6 +386,10 @@ $(document).ready(function(){
setTimeout( function () {window.location.reload();}, 300); setTimeout( function () {window.location.reload();}, 300);
} }
function reloadTable() {
asset_table.ajax.reload();
}
function doDeactive() { function doDeactive() {
var data = []; var data = [];
$.each(id_list, function(index, object_id) { $.each(id_list, function(index, object_id) {
...@@ -396,7 +400,7 @@ $(document).ready(function(){ ...@@ -396,7 +400,7 @@ $(document).ready(function(){
url: the_url, url: the_url,
method: 'PATCH', method: 'PATCH',
body: JSON.stringify(data), body: JSON.stringify(data),
success: refreshPage success: reloadTable
}); });
} }
function doActive() { function doActive() {
...@@ -409,7 +413,7 @@ $(document).ready(function(){ ...@@ -409,7 +413,7 @@ $(document).ready(function(){
url: the_url, url: the_url,
method: 'PATCH', method: 'PATCH',
body: JSON.stringify(data), body: JSON.stringify(data),
success: refreshPage success: reloadTable
}); });
} }
function doDelete() { function doDelete() {
...@@ -431,7 +435,7 @@ $(document).ready(function(){ ...@@ -431,7 +435,7 @@ $(document).ready(function(){
success: function () { success: function () {
var msg = "{% trans 'Asset Deleted.' %}"; var msg = "{% trans 'Asset Deleted.' %}";
swal("{% trans 'Asset Delete' %}", msg, "success"); swal("{% trans 'Asset Delete' %}", msg, "success");
refreshPage(); reloadTable();
}, },
flash_message: false, flash_message: false,
}); });
...@@ -478,16 +482,12 @@ $(document).ready(function(){ ...@@ -478,16 +482,12 @@ $(document).ready(function(){
'assets': id_list 'assets': id_list
}; };
var success = function () {
asset_table.ajax.reload()
};
var url = "{% url 'api-assets:node-remove-assets' pk=DEFAULT_PK %}".replace("{{ DEFAULT_PK }}", current_node_id); var url = "{% url 'api-assets:node-remove-assets' pk=DEFAULT_PK %}".replace("{{ DEFAULT_PK }}", current_node_id);
requestApi({ requestApi({
'url': url, 'url': url,
'method': 'PUT', 'method': 'PUT',
'body': JSON.stringify(data), 'body': JSON.stringify(data),
'success': success 'success': reloadTable
}) })
} }
......
...@@ -480,6 +480,11 @@ jumpserver.language = { ...@@ -480,6 +480,11 @@ jumpserver.language = {
last: "»" last: "»"
} }
}; };
function setDataTablePagerLength(num) {
$.fn.DataTable.ext.pager.numbers_length = num;
}
jumpserver.initDataTable = function (options) { jumpserver.initDataTable = function (options) {
// options = { // options = {
// ele *: $('#dataTable_id'), // ele *: $('#dataTable_id'),
...@@ -494,6 +499,7 @@ jumpserver.initDataTable = function (options) { ...@@ -494,6 +499,7 @@ jumpserver.initDataTable = function (options) {
// op_html: 'div.btn-group?', // op_html: 'div.btn-group?',
// paging: true // paging: true
// } // }
setDataTablePagerLength(5);
var ele = options.ele || $('.dataTable'); var ele = options.ele || $('.dataTable');
var columnDefs = [ var columnDefs = [
{ {
...@@ -590,8 +596,14 @@ jumpserver.initServerSideDataTable = function (options) { ...@@ -590,8 +596,14 @@ jumpserver.initServerSideDataTable = function (options) {
// columnDefs: [{target: 0, createdCell: ()=>{}}, ...], // columnDefs: [{target: 0, createdCell: ()=>{}}, ...],
// uc_html: '<a>header button</a>', // uc_html: '<a>header button</a>',
// op_html: 'div.btn-group?', // op_html: 'div.btn-group?',
// paging: true // paging: true,
// paging_numbers_length: 5;
// } // }
var pagingNumbersLength = 5;
if (options.paging_numbers_length){
pagingNumbersLength = options.paging_numbers_length;
}
setDataTablePagerLength(pagingNumbersLength);
var ele = options.ele || $('.dataTable'); var ele = options.ele || $('.dataTable');
var columnDefs = [ var columnDefs = [
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment