Giter Club home page Giter Club logo

bsqj's Introduction

pager.js - jQuery plugin

自动生成分页,自动加载table

#只需要很少的代码就能实现自动填充和分页

#初始化表格和分页

    $("#iplisttable").pagingTable({
        json_url: "{% url 'attendence:ip_json'%}",
        pageSize: 2,
        pageNumber: 10, /*default 10*/
        separator: "#" /*default #*/,
        callback: function(){console.log('this is callback...');}
    });

#version 2.1 changes: 1. 支持模板语法,指定分隔符,默认为 #
  1. 调整html结构,更符合一般的table结构

  2. 支持回调,在加载数据之后可以添加逻辑

  3. 支持自定义显示页码的个数,默认10个

#html结构范例:

    <table id="iplisttable" class="table table-bordered table-hover table-striped">
        <thead>
            <tr>
                <th width="20%">Name</th>
                <th width="20%">IP</th>
                <th width="20%">Action</th>
            </tr>
        </thead>
        <tbody>
            <tr pk="#ip#" template=1 style="display: none">
                <td>#name#</td>
                <td>#ip#</td>
                <td>
                    <a href="javascript:void(0)" onclick="delIP(this)" class="delip" style="cursor:pointer">
                        <span class="glyphicon glyphicon-floppy-remove"></span> <span>(#ip#)</span>
                    </a>
                    <a style="cursor:pointer;display:inline-block;margin-left:15px;">
                        <span class="glyphicon glyphicon-edit"></span>
                    </a>
                </td>
            </tr>
        </tbody>
    </table>

#后台数据接口

def ip_json(request):

    pagesize = int(request.GET.get('pagesize', 10))
    startindex = (int(request.GET.get('currentpage', 1)) - 1) * pagesize
    startindex = 0 if startindex < 0 else startindex
    endindex = startindex + pagesize

    totalRecords = EmployeeIP.objects.all().select_related().count()
    employeeips = EmployeeIP.objects.all().select_related()[startindex:endindex]
    data = [{"rownum": index + 1, "name": eip.employee.first_name + ' ' + eip.employee.last_name, "ip": eip.IP} for index, eip in enumerate(employeeips)]

    json_result = {
        "totalrecords": totalRecords,
        "data": data
    }
    return JsonResponse(json_result, safe=False)

bsqj's People

Contributors

wancy86 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.