Home Web Front-end HTML Tutorial Table control implemented by tbl.js div, completely free and does not rely on jquery

Table control implemented by tbl.js div, completely free and does not rely on jquery

Mar 12, 2017 pm 05:18 PM

There is a relatively easy-to-use form control on html, which is datatable, but the editing, buttons

and other parts are charged, and only the basic functions are free. Moreover, when the size changes, it requires manual refresh and other tedious operations. So I developed a free one for everyone to use.

This project has been used in the "VoidService Server Development Kit". Currently, it mainly supports Microsoft Edge browser, Chrome browser, others

have not been tested.

tbl.js is completely free and can be modified at will. Welcome for

k.

tbl.js supports list style, add, delete, modify, query, whole table search, grouping, paging function

, whole table editing, whole row Editing, single selection, multiple selection, style customization.

can be embedded in various containers, such as jquery

's dialog and tabs.

Version: 0.1beta

Report a bug and I will fix it as soon as possible. There is no break in the New Year.

If you do not need to modify the style, you do not need to load tbl.css, tbl.js will dynamically load the style sheet.

Let's create a two-row table, built from existing DOM nodes

.


1 html:<html><body><p></p></body></html>
2 new tbl(document.body.children[0],{data:[["row1"],["row2"]]});
Copy after login
Insert the self-created DOM node into the document body.


1 var tb = new tbl();
2 with (document.body) { insertBefore(tb.dom, firstChild) };
3 tb.bind([["row1"],["row2"]]);
Copy after login
For tables with multiple fields, the column widths are adaptive using percentages.


1 var tb = new tbl(undefined, {format:[{width:"20%"},{width:"20%"},{width:"20%"},{width:"20%"},{width:"20%"}]});
2 with (document.body) { insertBefore(tb.dom, firstChild) };
3 tb.bind([["row1","data","data","data","data"],["row2","data","data","data","data"]]);
Copy after login
List style, maximum height300px, no header, no title, no footer, 5 pieces of data, button, get rowindex.

This method will cause interlaced color changes, and the CSS can be modified to invalidate the style.


1 html:<html><body><p></p></body></html>
2 var tb = new tbl(document.body.children[0], {
3 editable: false, maxheight: "300px", header: false, title: false, footer: false, data: [[1], [2, "remove"], ["nan - not a number", "del"], [4, "del"], [5, "del"]], page_size: 100,
4 format: [
5      { width: "90%", nancenter: true, input: {type:"text"}},
6      { width: "10%", editable:true, input: { type: "button", value:"del", onclick: function () { tb.delete(tb.get_related_rowid(this));}}}
7      ]
8 });
Copy after login
Full table editing, single selection, one row must be selected, paging.

We initialize a data first. The data bound by tbl.js must be an array

.

I expect that the second column cannot be edited under any circumstances.


 1 var tb_data = [];
 2 for (var i = 0; i < 106; i++) {
 3      tb_data[i] = [Math.random()>0.5?true:false, Math.random(), "1970-01-01", Math.floor(Math.random()*10), i, 0];
 4 }
 5 tb_data[i] = "this is group"; i++;
 6 tb_data[i] = ["this is text"]; i++;
 7 for (; i < 578; i++) {
 8      tb_data[i] = [i, Math.random(), "2017-02-01"];
 9 }
10 var tb = new tbl(document.body.children[0], {
11      editable:true,select:tbl.single,must_select:true,paging:true,data:tb_data,page_size:15,
12      format: [
13          { width: "5%", input: { type: "checkbox", check: "true" } },
14          { width: "30%", name:"name", uneditable:true },
15          { width: "20%", name:"date", input: { type: "date" } },
16          { width: "10%", name:"select", input: {type:"select", options:[0,1,2,3,4,5,6,7,8,9]} },
17          { width: "20%" },
18          { width: "15%", input: {type:"radio", name:"only"}}
19      ]
20 });
Copy after login
API:

add is added at the end. The added row of data must be an array. Non-array will be used as the group title text.

insert Insert data

bind bind new data source

delete Delete

one row

clear

Clean up

edit Edit a row, empty parameter means edit the entire table

select Select a row

cancel_edit Cancel editing

cancel_select Cancel selection

select_change Select to changeFunction

Settings

Read-onlyAttributes

:

tbl::selects Selected rows

tbl::data data

tbl::dom DOM node

tbl::edits The row being edited, full table editing is not applicable

Construction options:


max_height Maximum height, scroll bars will be displayed if it exceeds
page_size Page size
data Initialization data
header Whether to display the header
footer Whether to display the footer
info Whether to display information
paging Whether to display paging
title_bar Display title bar
title Title bar text
search Display search box
editable Full table editing
select Type of selection: 0, cannot be selected. 1, radio selection . 2, multi-select.tbl.single == 1, tbl.multiselect == 2 select_change Set selectionEvent processing
Function
must_select Must select a row
format Column format
width Width, can be a valid html width. For example: 100px or 20%. input is used to edit the input node attribute of status
, which is the same as the html/input attribute
name field name, displayed in the header
uneditable columns will not be able to Edited
editable columns will always be in editable state

nancenter Non-numeric centering###

The above is the detailed content of Table control implemented by tbl.js div, completely free and does not rely on jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

See all articles