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
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 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! ! !

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Enhance Your Code Presentation: 10 Syntax Highlighters for Developers Sharing code snippets on your website or blog is a common practice for developers. Choosing the right syntax highlighter can significantly improve readability and visual appeal. T

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

This article presents a curated selection of over 10 tutorials on JavaScript and jQuery Model-View-Controller (MVC) frameworks, perfect for boosting your web development skills in the new year. These tutorials cover a range of topics, from foundatio

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
