npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xq-treegrid

v1.0.7

Published

一个基于Bootstrap5和html5sortable的可拖动排序的树状表格列表。

Downloads

12

Readme

xq-treegrid

一个基于Bootstrap5的树状表格列表,采用异步加载节点的方式,可以在HTML的Table中显示树状数据,并支持添加、更新、删除等操作,同时还可以拖动排序。

安装与使用

npm i xq-treegrid

typescript方式

在typescript代码中引入xq-treegrid的代码

import xqTreegrid from 'xq-treegrid';

同时还需要在HTML页面代码中引入xq-treegrid的scss代码

javascript方式

同时还需要在HTML页面代码中引入xq-treegrid的css代码

导入后在相应的HTML文件代码中的Table标签添加class="xq-treegrid"的属性就可以自动运行。 如果想要开启看拖动排序,需要以class属性添加“xq-drag”,例如:class="xq-treegrid xq-drag"。

备注说明

在相应的页面还得引入bootstrap的js和css文件。

元素的id规则为:字段名称_id编号

tbody里的tr的属性包括:depth、is_leaf、id、pid、class。

具体情况参考示例代码

HTML示例代码

<form enctype="application/json" method="post">
    <div class="table-responsive">
        <table  class="table table-bordered xq-table-hover xq-table-striped xq-treegrid xq-drag">
        <thead>
            <tr>
                <th style="width:60px;">选择</th>
                <th style="text-align: left;">栏目名称</th>
                <th style="width:60px;">类型</th>
                <th style="width:60px;">状态</th>
                <th style="width:170px;">操作</th>
            </tr>
        </thead>
        <tbody>
            <tr depth="1" is_leaf="0" id="xq_58cb49e77e5239062c000a43" pid="58514b454a495f524f4f5430" class="xq-treegrid-top">
                <td>
                    <input type="checkbox" id="58cb49e77e5239062c000a43[id]" name="58cb49e77e5239062c000a43[id]" value="58cb49e77e5239062c000a43" class="form-check-input">
                </td>
                <td style="text-align:left;">
                    
                    <input type="text" id="name_58cb49e77e5239062c000a43" name="58cb49e77e5239062c000a43[name]" value="栏目1" class="form-control" style="width:200px;" required="1" placeholder="请输入一个标题">
                </td>
                <td>栏目</td>
                <td style="vertical-align: middle;">
                    <div style="width:32px;margin:auto;" class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" id="status_58cb49e77e5239062c000a43" name="58cb49e77e5239062c000a43[status]" checked>
                    </div>
                    
                </td>
                <td>
                    <input type="button" value="复制" class="btn btn-primary btn-sm xq-copy"><input type="button" value="设置" class="btn btn-primary btn-sm xq-edit"><input type="button" value="删除" class="btn btn-danger btn-sm xq-delete">
                </td>
            </tr>
            <tr depth="1" is_leaf="0" id="xq_58d8baa17e52391108000a38" pid="58514b454a495f524f4f5430" class="xq-treegrid-top xqkeji-treegrid-expanded">
                <td>
                    <input type="checkbox" id="58d8baa17e52391108000a38[id]" name="58d8baa17e52391108000a38[id]" value="58d8baa17e52391108000a38" class="form-check-input">
            
                </td>
                <td style="text-align:left;">
                    
                    <input type="text" id="name_58d8baa17e52391108000a38" name="58d8baa17e52391108000a38[name]" value="栏目2" class="form-control" style="width:200px;" required="1" placeholder="请输入一个标题">
                </td>
                <td>栏目</td>
                <td style="vertical-align: middle;">
                    <div style="width:32px;margin:auto;" class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" id="status_58d8baa17e52391108000a38" name="58d8baa17e52391108000a38[status]">
                    </div>
                    
                </td>
                <td>
                    <input type="button" value="复制" class="btn btn-primary btn-sm xq-copy"><input type="button" value="设置" class="btn btn-primary btn-sm xq-edit"><input type="button" value="删除" class="btn btn-danger btn-sm xq-delete">
                </td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td>
                    <input type="checkbox" class="xq-check-all form-check-input">
                    
                </td>
                <td colspan="99" style="text-align:left;">
                    <button  type="button" class="btn btn-primary xq-add" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-trigger="hover" data-bs-html="true" title="没选中时,添加顶级栏目;<br/>有选中时,添加子栏目。">添加</button>
                </td>
            </tr>
        </tfoot>
        </table>
    </div>
</form>	

本组件需要自己显示第一层的数据,第二层以上的数据会异步自动加载。

相关的处理接口

加载子节点的数据: /subnode/父节点的id。

返回信息示例:

[
    {
        "id":"58cb49e77e5239062c000001",
        "name": "栏目1-1",
        "depth": 2,
        "is_leaf":1,
        "pid":"58cb49e77e5239062c000a43",
        "status":1,
        "type":1,
        "content":"<td><input type=\"checkbox\" id=\"id_58cb49e77e5239062c000001\" name=\"58cb49e77e5239062c000001[id]\" value=\"58cb49e77e5239062c000001\" class=\"form-check-input\"></td><td style=\"text-align:left;\"><input type=\"text\" id=\"name_58cb49e77e5239062c000001\" name=\"58cb49e77e5239062c000001[name]\" value=\"栏目1-1\" class=\"form-control\" style=\"width:200px;\" required=\"1\" ></td><td>栏目</td><td><div class=\"form-check form-switch\"><input class=\"form-check-input\" type=\"checkbox\" id=\"status_58cb49e77e5239062c000001\" name=\"58cb49e77e5239062c000001[status]\" checked=\"\"></div></td><td><input type=\"button\" value=\"复制\" class=\"btn btn-primary btn-sm xq-copy\"><input type=\"button\" value=\"设置\" class=\"btn btn-primary btn-sm xq-edit\"><input type=\"button\" value=\"删除\" class=\"btn btn-danger btn-sm xq-delete\"></td>"
    }
]
添加子节点: /add

post信息:{"pid":""}父节点的id 有选中相应节点后再添加时,添加子节点 没有选中则添加第一层的节点

返回信息示例:

{
    "id":"",
    "name": "",
    "depth": 2,
    "is_leaf":1,
    "pid":"",
    "status":1,
    "type":1,
    "content":""
}

需要根据添加时提供的父节点id,动态返回数据。特别是depth、is_leaf、content会影响到显示。

修改数据: /change

post信息:{id: "节点的id", field:"更改的字段名称",value: "最新的值"} 返回信息示例:

{
    "success":true,
    "message": "栏目保存成功.",
    "code": 200
}
删除数据: /delete

post信息:{id: "节点的id"} 返回信息示例:

{
    "success":true,
    "message": "删除成功.",
    "code": 200
}
移动节点: /move

post信息: { "id": "58d8baa17e52391108000a38", //拖动节点的id "pid": "58514b454a495f524f4f5430",//拖动后节点的父节点id "nextid": "58cb49e77e5239062c000a43"//拖动后下一个邻居节点的id } 返回信息示例:

{
    "success":true,
    "message": "栏目移动成功.",
    "code": 200
}