haystack-core
Advanced tools
Comparing version 2.0.12 to 2.0.15
@@ -367,2 +367,8 @@ import { HVal, OptionalHVal } from './HVal'; | ||
/** | ||
* Synchronize column meta information from this grid to the specified grid. | ||
* | ||
* @param grid The grid to synchronize data to. | ||
*/ | ||
private syncColumnMeta; | ||
/** | ||
* Filters an individual column in a grid. | ||
@@ -542,3 +548,3 @@ * | ||
* // Map each row to a div using React... | ||
* grid.map((dict: HDict): any => <div>{dict.toZinc()}</div>>) | ||
* grid.map((dict: HDict) => <div>{dict.toZinc()}</div>>) | ||
* ``` | ||
@@ -756,20 +762,2 @@ * | ||
/** | ||
* Remove the column via its name or index number. | ||
* | ||
* If the column is successfully removed return its instance. Otherwise | ||
* return undefined. | ||
* | ||
* ```typescript | ||
* // Remove the column via its name | ||
* grid.remove('Address) | ||
* | ||
* // Alternatively remove the column via its index number in the grid. | ||
* grid.remove(1) | ||
* ``` | ||
* | ||
* @param name The name or index number of the grid column to remove. | ||
* @returns The removed column or undefined if nothing is removed. | ||
*/ | ||
removeColumn(name: string | number): GridColumn | undefined; | ||
/** | ||
* Set the column at the specified index number. | ||
@@ -864,2 +852,15 @@ * | ||
/** | ||
* Limit the grid only to the specified columns. | ||
* | ||
* This will return a new instance of a grid. | ||
* | ||
* ```typescript | ||
* grid.filter('site').limitColumns(['id', 'dis']).inspect() | ||
* ``` | ||
* | ||
* @param names The column names. | ||
* @returns A new grid instance with the specified columns. | ||
*/ | ||
limitColumns<LimitDictVal extends HDict = DictVal>(names: string[]): HGrid<LimitDictVal>; | ||
/** | ||
* Iterate over a grid using dicts for rows. | ||
@@ -893,2 +894,22 @@ * | ||
/** | ||
* Selects a range from the grid. | ||
* | ||
* The start and end can be used to specify a range... | ||
* ```typescript | ||
* // from [0, 1, 2, 3, 4, 5] to [1, 2, 3, 4] | ||
* grid.filter('site').range(1, 4).inspect() | ||
* ``` | ||
* | ||
* //If only the first argument then a quantity can be used... | ||
* ```typescript | ||
* // select the first 4 rows - [0, 1, 2, 4]... | ||
* grid.filter('site').range(4).inspect() | ||
* ``` | ||
* | ||
* @param startOrQuantity The start of the range or quantity. | ||
* @param end Optional end range. | ||
* @returns This grid instance. | ||
*/ | ||
range(startOrQuantity: number, end?: number): this; | ||
/** | ||
* Return the sum of values for the specified column. | ||
@@ -1023,6 +1044,2 @@ * | ||
/** | ||
* Rebuild the column cache. | ||
*/ | ||
private rebuildColumnCache; | ||
/** | ||
* @returns Returns a copy of the grid. | ||
@@ -1029,0 +1046,0 @@ */ |
@@ -14,3 +14,3 @@ { | ||
"email": "support@j2inn.com", | ||
"version": "2.0.12", | ||
"version": "2.0.15", | ||
"module": "dist/index.es.js", | ||
@@ -17,0 +17,0 @@ "main": "dist/index.js", |
@@ -15,3 +15,3 @@ # Haystack Core | ||
- [Haystack units](https://github.com/j2inn/haystack-units): all haystack units. | ||
- [Haystack client](https://github.com/j2inn/haystack-client): a client network library used for working with a haystack server. | ||
- [Haystack nclient](https://github.com/j2inn/haystack-nclient): a client network library used for working with a haystack server. | ||
- [Haystack react](https://github.com/j2inn/haystack-react): a set of high level [React](https://reactjs.org/) hooks and utilities for working with haystack data. | ||
@@ -27,2 +27,4 @@ | ||
Please click [here](http://j2-docs.s3-website-us-east-1.amazonaws.com/j2inn/haystack-core/index.html) for the API documentation. | ||
### Core Types | ||
@@ -29,0 +31,0 @@ |
@@ -1038,2 +1038,3 @@ /* | ||
this.syncColumnMeta(grid) | ||
return grid | ||
@@ -1043,2 +1044,18 @@ } | ||
/** | ||
* Synchronize column meta information from this grid to the specified grid. | ||
* | ||
* @param grid The grid to synchronize data to. | ||
*/ | ||
private syncColumnMeta(grid: HGrid): void { | ||
for (const col of this.getColumns()) { | ||
const newCol = grid.getColumn(col.name) | ||
if (newCol && !newCol.meta.equals(col.meta)) { | ||
newCol.meta.clear() | ||
newCol.meta.update(col.meta) | ||
} | ||
} | ||
} | ||
/** | ||
* Filters an individual column in a grid. | ||
@@ -1175,2 +1192,3 @@ * | ||
grid.add(rows as DictVal[]) | ||
this.syncColumnMeta(grid) | ||
} | ||
@@ -1476,3 +1494,3 @@ | ||
* // Map each row to a div using React... | ||
* grid.map((dict: HDict): any => <div>{dict.toZinc()}</div>>) | ||
* grid.map((dict: HDict) => <div>{dict.toZinc()}</div>>) | ||
* ``` | ||
@@ -1855,39 +1873,2 @@ * | ||
/** | ||
* Remove the column via its name or index number. | ||
* | ||
* If the column is successfully removed return its instance. Otherwise | ||
* return undefined. | ||
* | ||
* ```typescript | ||
* // Remove the column via its name | ||
* grid.remove('Address) | ||
* | ||
* // Alternatively remove the column via its index number in the grid. | ||
* grid.remove(1) | ||
* ``` | ||
* | ||
* @param name The name or index number of the grid column to remove. | ||
* @returns The removed column or undefined if nothing is removed. | ||
*/ | ||
public removeColumn(name: string | number): GridColumn | undefined { | ||
let index = -1 | ||
if (typeof name === 'string') { | ||
for (let i = 0; i < this.$store.columns.length; ++i) { | ||
if (this.$store.columns[i].name === (name as string)) { | ||
index = i | ||
break | ||
} | ||
} | ||
} else { | ||
index = name as number | ||
} | ||
const col = | ||
index >= 0 ? this.$store.columns.splice(index, 1)[0] : undefined | ||
this.rebuildColumnCache() | ||
return col | ||
} | ||
/** | ||
* Set the column at the specified index number. | ||
@@ -2039,2 +2020,42 @@ * | ||
/** | ||
* Limit the grid only to the specified columns. | ||
* | ||
* This will return a new instance of a grid. | ||
* | ||
* ```typescript | ||
* grid.filter('site').limitColumns(['id', 'dis']).inspect() | ||
* ``` | ||
* | ||
* @param names The column names. | ||
* @returns A new grid instance with the specified columns. | ||
*/ | ||
public limitColumns<LimitDictVal extends HDict = DictVal>( | ||
names: string[] | ||
): HGrid<LimitDictVal> { | ||
return HGrid.make<LimitDictVal>({ | ||
version: this.version, | ||
meta: this.meta.newCopy() as HDict, | ||
rows: this.getRows().map( | ||
(dict: DictVal): LimitDictVal => { | ||
const newDict = new HDict() | ||
for (const name of names) { | ||
if (dict.has(name)) { | ||
newDict.set(name, dict.get(name) as HVal) | ||
} | ||
} | ||
return newDict as LimitDictVal | ||
} | ||
), | ||
columns: this.getColumns() | ||
.filter((col: GridColumn) => names.includes(col.name)) | ||
.map((col: GridColumn): { | ||
name: string | ||
meta?: HDict | ||
} => ({ name: col.name, meta: col.meta.newCopy() as HDict })), | ||
}) | ||
} | ||
/** | ||
* Iterate over a grid using dicts for rows. | ||
@@ -2074,2 +2095,40 @@ * | ||
/** | ||
* Selects a range from the grid. | ||
* | ||
* The start and end can be used to specify a range... | ||
* ```typescript | ||
* // from [0, 1, 2, 3, 4, 5] to [1, 2, 3, 4] | ||
* grid.filter('site').range(1, 4).inspect() | ||
* ``` | ||
* | ||
* //If only the first argument then a quantity can be used... | ||
* ```typescript | ||
* // select the first 4 rows - [0, 1, 2, 4]... | ||
* grid.filter('site').range(4).inspect() | ||
* ``` | ||
* | ||
* @param startOrQuantity The start of the range or quantity. | ||
* @param end Optional end range. | ||
* @returns This grid instance. | ||
*/ | ||
public range(startOrQuantity: number, end?: number): this { | ||
const rows = this.getRows() | ||
if (end === undefined) { | ||
end = --startOrQuantity | ||
startOrQuantity = 0 | ||
} | ||
if (startOrQuantity <= end) { | ||
for (let i = rows.length; i >= 0; --i) { | ||
if (i < startOrQuantity || i > end) { | ||
this.remove(i) | ||
} | ||
} | ||
} | ||
return this | ||
} | ||
/** | ||
* Return the sum of values for the specified column. | ||
@@ -2266,9 +2325,2 @@ * | ||
/** | ||
* Rebuild the column cache. | ||
*/ | ||
private rebuildColumnCache(): void { | ||
this.$store.rebuildColumnCache() | ||
} | ||
/** | ||
* @returns Returns a copy of the grid. | ||
@@ -2275,0 +2327,0 @@ */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
1526029
0
100
52285
124
112