如果没有显示记录/总记录数,如何在DataTables中继续显示分页栏?

时间:2017-06-30 15:15:50

标签: javascript jquery html css datatables

我正在使用from PySide import QtCore, QtGui import matplotlib matplotlib.use('Qt4Agg') matplotlib.rcParams['backend.qt4']='PySide' from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar from matplotlib.figure import Figure from mpl_toolkits.basemap import Basemap from random import randint class MapWidget(QtGui.QWidget): def __init__(self, parent=None): super().__init__(parent) self.figure = Figure() self.canvas = FigureCanvas(self.figure) self.layout = QtGui.QVBoxLayout(self) self.mplToolbar = NavigationToolbar(self.canvas, self, coordinates=False) self.layout.addWidget(self.canvas) self.layout.addWidget(self.mplToolbar) self.axes = self.figure.add_subplot(111) self.setLayout(self.layout) # Create our Basemap self.map = Basemap(projection='robin', lon_0=0, ax=self.axes, resolution='c') self.map.drawcoastlines() self.map.drawcountries() self.canvas.draw() self.show() def changeMap(self, lat, lon): # I'm saving the supposedly 'clean' Basemap to a variable and plotting on that newMap = self.map x, y = newMap(lon, lat) newMap.plot(x, y, 'o') self.canvas.draw() class Ui_MainWindow(object): def plot(self): # Plot on some random coordinate self.Map.changeMap(randint(-90, 90), randint(-180, 180)) def myChanges(self): # Initialize our Basemap self.Map = MapWidget() self.layoutMap = QtGui.QVBoxLayout(self.widget) self.layoutMap.addWidget(self.Map) # Plot a new point when the button is clicked self.pushButton.clicked.connect(self.plot) # The following is all PySide code, not very relevant to the question def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.pushButton = QtGui.QPushButton(self.centralwidget) self.pushButton.setMaximumSize(QtCore.QSize(100, 16777215)) self.pushButton.setObjectName("pushButton") self.horizontalLayout.addWidget(self.pushButton) self.widget = QtGui.QWidget(self.centralwidget) self.widget.setObjectName("widget") self.horizontalLayout.addWidget(self.widget) self.horizontalLayout_2.addLayout(self.horizontalLayout) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.myChanges() def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Plot", None, QtGui.QApplication.UnicodeUTF8)) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) ,如果没有记录或者正在显示总记录数,我需要一直显示分页栏。目前,如果没有记录并且是否显示记录总数,则分页栏会隐藏。在这两种情况下都不需要分页,但是在两种情况下都有一个属性可以使分页栏就位。我的JQuery看起来像下面的

JQuery的

DataTables

由于

1 个答案:

答案 0 :(得分:0)

如果只有一个页面,您可以检索页数并显示隐藏的分页控件。

var table = $('#example').DataTable({
   pagingType: 'input',
   drawCallback: function(){
       var api = this.api();
       var container = api.table().container();

       var info = api.page.info();
       if(info.pages === 1){
           $('.dataTables_paginate', container).show();
           $('.paginate_input, .paginate_page', container).hide();
       } else {           
           $('.paginate_input, .paginate_page', container).show();          
       }
   }
});

请参阅this example以获取代码和演示。