How to generate serial number in javascript

This should do it:

function getNext[num] {
    var alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
    var digits = num.toUpperCase[].split[""],
        len = digits.length,
        increase = true;
    if [len != 3]
        throw new Error["Invalid serial number length in getNext: "+num];
    for [var i=len-1; increase && i>=0; i--] {
        var val = alphabet.indexOf[digits[i]];
        if [val == -1]
            throw new Error["Invalid serial number digit in getNext: "+num];
        val++;
        if [val < alphabet.length] {
            digits[i] = alphabet[val];
            increase = false;
        } else { // overflow
            digits[i] = alphabet[0];
        }
    }
    if [increase] // is still true
        throw new Error["Serial number overflow in getNext"];
    num = digits.join[""];
    return num;
}

Since you are working with a nearly alphanumeric alphabet, a parseInt/toString with radix 33 might have done it as well. Only you need to "jump" over the 0, I and O, that means replacing 0,A,B… by A,B,C…, replacing H,I,J… by J,K,L… and replacing M,N,O… by P,Q,R… [and everything back on deserialisation] - which might be OK if JS has a numeric char datatype, but I think it's easier to do it manually as above.

If you're curious:

String.prototype.padLeft = function[n, x] {
     return [new Array[n].join[x || "0"]+this].slice[-n];
};
function getNext[num] {
    var alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
    var back = {}, forth = {};
    for [var i=0; iOther>Insert Row Policy to the Original

2. Set loading end event

In the menu bar, click Template> Web Attributes > Data Entry Settings, choose Individually set for the template, and add the loading End event,as shown in the following figure:

The JavaScript code is as follows:

var $tds = $['.x-table td[col=0][fm="SEQ[]"]:visible']; 
//Get the serial number cell visible in column 1 [column A]
var n = 0;
$tds.each[function[i, e] {
n = n + 1;
$[e].text[n]; 
//Reset the current number
}]

The core statement in this JS is $['.x-table td[col=0][fm="SEQ[]"]:visible'], the description is as follows:

col=0: Get the first column [column A]

fm="SEQ[]": Get the cell where the seq[] formula is written [the case of SEQ[] in JS must be consistent with the formula in the template]

visible: Get visible cells [excluding hidden rows]

3. Effect preview

Save the report, click Data Entry Preview, the effect is as shown in the figure below:

III. Template download

IV. Precautions

The serial number displayed in the above scheme after inserting and deleting rows is the displayed value, and cannot be submitted to the dataset, and is only used as a page display effect. If you want to submit the serial number to the warehouse at the same time, you need to assign the actual value to the corresponding cell. The specific solution is to replace the JavaScript code in the loading end event with the following code:

var $tds = $['.x-table td[col=0][idx=0]:visible:not[[fmt="T"]]'];
//Get the serial number cell visible in column 1 [column A]
var n = 0;
$tds.each[function[i, e] {
n = n + 1;
var row = $[e].attr["row"];
//Get line number
_g[].setCellValue[0, 0, row, n];
//Reset the current number
}]

The core statement in this JS is $['.x-table td[col=0][idx=0]:visible:not[[fmt="T"]]'], the description is as follows:

col=0: Get the first column [column A]

idx=0: Eliminate the interfering elements below the serial number cell, the fixed wording does not need to be modified

not[[fmt="T"]]: exclude the title element above the serial number cell, the fixed wording does not need to be modified

visible: Get visible cells [excluding hidden rows]

Note: Using this scheme to assign actual values to the serial number cells will cause page jams when the amount of data is large, so you need to consider whether to use it according to the actual situation.

How is serial number generated?

Generate Serial Numbers by Adding One in the Previous Number Enter 1 in the cell from where you want to start your serial numbers. In next down cell, enter formula =G1+1 [G1 is the starting cell here]. Drag this formula to down, up to the serial numbers you want.

How use Javascript serial number?

jQuery Method to add automating serial number for each row each[function[]{ $['th:first-child, thead td:first-child', this]. each[function[]{ var tag = $[this]. prop['tagName']; $[this]. before['#']; }]; $['td:first-child', this].

What is a serial number in math?

Serial number. A serial number is a unique code assigned for identification of a single unit. Although usually called a number, it may include letters, though ending with digits. Typically serial numbers of a production run are incremented by one, or another fixed difference, from one unit to the next.

Chủ Đề