Plug-in for dynamically creating tables based on jquery_jquery
Without further ado, go straight to the topic,
Table functions:
1. Add
2. Delete
3. Get value
4. Dynamically fill data
5. Dynamically set focus
6. Use the left and right keys on the keyboard to control cell focus
7. Add regular validation function to cells
WebForm4.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="table.WebForm4" %>
jquery.DynamicTable.js
///
2
3 (function($) {
4 var rowtmplate = " ";
5 var arrFocus = [];
6
7 $.fn.DynamicTable = function(options) { //Define the name of the plug-in, here is userCp
8 var deafult = {
9 //The following are the properties of the plug-in and their default values
rowCount: 5, //Add the number of rows
identity: 1, //The first column is automatically numbered
arrFocus: [2, 1 ], //The first cell is set as focus
rowTmplate: "" //Row template
};
var ops = $.extend(deafult, options);
rowtmplate = ops. rowTmplate;
arrFocus = ops.arrFocus;
$(this).addRow(ops.rowCount);
};
/*Add multiple rows after the last row of the table through the row template*/
/*count--Add row count*/
$.fn.addRow = function(options) {
var deafult = {
rowCount: 5
};
var ops = $.extend(deafult, options);
var rowData = "";
var count = ops.rowCount;
for (var i = 1; i <= count; i ) {
rowData = rowtmplate;
}
$(this).find('tr:last-child').after(rowData);
CellsFocus();
};
/*Dynamic Bind an event to a column, and execute the fn function when the event is triggered*/
/*eventName--event name; colIndex--column index (starting from 1); fn--trigger function*/
$. fn.BindEvent = function(options) {
var deafult = {
eventName: 'click',
colIndex: 1,
fn: function() { alert('You clicked this unit Grid!') }
};
var ops = $.extend(deafult, options);
eventName = ops.eventName;
colIndex = ops.colIndex;
fn = ops. fn;
$("tr:gt(0) td:nth-child(" colIndex ")").bind(eventName, fn);
};
/*Bind order to a certain column Click delete event*/
/*colIndex--column index (starting from 1)*/
$.fn.deleteRow = function(options) {
var deafult = {
colIndex: 6
};
var ops = $.extend(deafult, options);
var colIndex = ops.colIndex;
$("tr:gt(0) td:nth-child(" colIndex " )").bind("click", function() {
var obj = $(this).parent(); //Get the tr child node object
if (confirm('Are you sure you want to delete it?'))
obj.remove();
});
};
/*Automatically fill in the serial number for the specified column*/
/*colIndex--column index (starting from 1 )*/
$.fn.Identity = function(options) {
var deafult = {
colIndex: 1
};
var ops = $.extend(deafult, options);
var colIndex = ops.colIndex;
var i = 1;
$("td:nth-child(" colIndex ")").find('input').each(function() {
$(this).attr('value', i)
i ;
});
};
/*Get focus cell coordinates*/
$.fn .getFocus = function() {
return arrFocus;
};
/*Set focus cell coordinates*/
/*rowIndex--row index (starting from 1); colIndex--column Index (starting from 1)*/
$.fn.setFocus = function(options) {
var deafult = {
rowIndex: 2,
colIndex: 1
};
var ops = $.extend(deafult, options);
var rowIndex = ops.rowIndex;
var colIndex = ops.colIndex;
arrFocus[0] = rowIndex;
arrFocus[1] = colIndex;
};
/*When data is entered into a cell, after pressing the Enter key, the data is automatically retrieved from the background and filled in the corresponding column of the row according to the entered value*/
/*colIndex-- In which column of input data, press the Enter key to trigger the event; fn--callback function with parameters*/
$.fn.AutoFillData = function(options) {
colIndex = options.colIndex;
fn = options .fn;
$("td:nth-child(" colIndex ")").bind("keyup", function() {
var obj = $(this).parent(); //Get tr child node object
$(this).find('input').each(function() {
if (event.keyCode == 13) {
var vl = $(this).val ();
var arr = new Array();
arr = fn(vl);
var i = 0;
obj.find("td").each(function() {
$(this).find("input").each(function() {
$(this).attr('value', arr[i]);
i ;
} );
});
}
});
});
};
/*Set a cell as focus*/
/*rowIndex- -Row index (starting from 1);colIndex--column index (starting from 1)*/
$.fn.setCellsFocus = function(options) {
var deafult = {
rowIndex: arrFocus[0 ],
colIndex: arrFocus[1]
};
var ops = $.extend(deafult, options);
var rowIndex = ops.rowIndex;
var colIndex = ops.colIndex ;
$("tr:nth-child(" rowIndex ") td:nth-child(" colIndex ")").each(function() {
$(this).find('input') .each(function() {
$(this)[0].focus();
$(this).attr('value', $(this).attr('value'));
arrFocus = [];
arrFocus.push(rowIndex);
arrFocus.push(colIndex); //Update focus array value
});
});
};
/*Set the text value of a certain cell to the selected state*/
/*rowIndex--row index (starting from 1); colIndex--column index (starting from 1)*/
$. fn.setCellsSelect = function(options) {
var deafult = {
rowIndex: arrFocus[0],
colIndex: arrFocus[1]
};
var ops = $.extend( deafult, options);
var rowIndex = ops.rowIndex;
var colIndex = ops.colIndex;
$("tr:nth-child(" rowIndex ") td:nth-child(" colIndex " )").each(function() {
$(this).find('input').each(function() {
$(this)[0].select();
} );
});
};
/*Add validation function to a certain cell*/
/*reg--regular expression;colIndex--column index (starting from 1); defaultValue--The default value assigned to the cell if validation fails*/
$.fn.validationText = function(options) {
var deafult = {
reg: /^((d .d{2})| d )$/,
colIndex: 2,
defaultValue: 0
};
var ops = $.extend(deafult, options);
var reg = ops.reg;
var colIndex = ops.colIndex;
var defaultValue = ops.defaultValue;
$("tr:gt(0) td:nth-child(" colIndex ")").each(function() {
$(this).find('input').each(function() {
//Verification
$(this).bind('blur', function() {
var vl = $(this).attr('value');
if (!reg.test(vl))
$(this).attr('value', defaultValue);
});
});
});
};
/*Get the value in the table*/
$.fn.getValue = function(options) {
var deafult = {
rowIndex: 0, //Row coordinates (starting from 2)
colIndex: 0 //Column coordinates (starting from 1)
};
var ops = $.extend(deafult, options);
rowIndex = ops.rowIndex;
colIndex = ops.colIndex;
var val = "";
if (rowIndex == 0) { //Get data for all rows
$(' tr:gt(0)').each(function() {
$(this).find("td").each(function() {
$(this).find("input") .each(function() {
val = $(this).attr('value') "&";
});
});
val = val.substring(0, val.length - 1) "|";
});
}
else {
if (colIndex == 0) { //Get a row of data
$('tr: nth-child(' rowIndex ')').each(function() {
$(this).find("td").each(function() {
$(this).find("input ").each(function() {
val = $(this).attr('value') "&";
});
});
val = val.substring( 0, val.length - 1) "|";
});
}
else { //Get the value of a cell
$("tr:nth-child(" rowIndex ") td:nth-child(" colIndex ")").each(function() {
$(this).find('input').each(function() {
val = $(this ).attr('value');
});
});
}
}
return val;
};
/*Update focus coordinates after a cell gets focus*/
function CellsFocus() {
var colCount = $("tr:nth-child(1) td").size() ; //Get how many cells there are in each row
$("tr:gt(0) td").each(function() {
var obj = $(this);
$(this ).find('input').each(function() {
$(this).bind('focus', function() {
var cellTotal = $('td').index(obj) ; //Get the index of a certain cell
arrFocus[0] = parseInt(cellTotal / colCount) 1; //Which row
arrFocus[1] = cellTotal % colCount 1; //Which column
});
});
});
};
})(jQuery);
getData.ashx
using System;
using System.Collections.Generic;
using System.Linq ;
using System.Web;
using System.Web.Services;
namespace table
{
///
/// Summary description of $codebehindclassname$
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class getData : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
string value = GetResult();
context.Response.Write( value);
context.Response.End();
}
private string GetResult()
{
string result = string.Empty;
result = @"
[{""id"":""1"",""Name"":""Green Tea"",""Code"":""1371"",""Units"":""jin"", ""Price"":""200""},
{""id"":""2"",""Name"":""Black Tea"",""Code"":""1372 "",""Units"":""jin"",""Price"":""300""},
{""id"":""3"",""Name"": ""Tea Set"",""Code"":""1373"",""Units"":""台"",""Price"":""20000""},
{""id "":""4"",""Name"":""Tieguanyin"",""Code"":""1374"",""Units"":""Bottle"",""Price" ":""400""},
{""id"":""5"",""Name"":""tea bag"",""Code"":""1375"" ,""Units"":""Box"",""Price"":""500""},
{""id"":""6"",""Name"":"" Tea Food"",""Code"":""1376"",""Units"":""Box"",""Price"":""400""},
{""id" ":""7"",""Name"":""Packaging bag"",""Code"":""1377"",""Units"":""Box"",""Price"" :""100""}]";
return result;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
style2.css
/* ---------- Page style definition---------- */
body
{
background- color:#ffffff;
MARGIN:0px;
font-size: 10pt; /* font size*/
font-family:Verdana; /* font name*/
}
/ * ---------- Text link - the normal state of the link ---------- */
A:link {
color: #0000FF;
TEXT- DECORATION: none;}
/* ---------- Text link - visited link ---------- */
A:visited {
COLOR : #0000FF;
TEXT-DECORATION: none}
/* ---------- Text link - active link ---------- */
A:active {
COLOR: #3333ff;
TEXT-DECORATION: none}
/* ---------- Text link - the pointer is on the link ------- --- */
A:hover {
COLOR: #ff0000;
text-decoration: underline;}
/* ---------- Table style 1 (normal Table) ---------- */
.tablestyle1{
font-size: 9pt; /* Font size in the table*/
width: 100%; /* Table width* /
border: 0px none; /* Table border width*/
background-color: #0077B2; /* Table line color*/
cellSpacing:expression(this.cellSpacing=1); /* Two The distance between cells*/
cellPadding:expression(this.cellPadding=3); }
.TableData {
BACKGROUND: #FFFFFF;
FONT-SIZE: 10pt;
}
Since I don’t know how to upload files, I have to post the code. Please forgive me! ! !

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.
