jqgrid_utils
v1.40.2
Published
Convenient Functions for the Free jqGrid
Maintainers
Readme
jqgrid_utils
Convenient Utility Functions for Free jqGrid
jqgrid_utils is a JavaScript library designed to simplify common tasks and enhance the functionality of free jqGrid, a powerful jQuery grid plugin. It provides a collection of utility functions that can help you streamline your jqGrid implementations, reduce boilerplate code, and improve the overall user experience.
Features
- Simplified jqGrid Initialization: Provides helper functions to easily configure and initialize jqGrid instances with common settings.
- Data Formatting Utilities: Offers functions for formatting data displayed in the grid, such as dates, numbers, and currencies.
- CRUD Operation Helpers: Simplifies the implementation of Create, Read, Update, and Delete (CRUD) operations with jqGrid, including handling form submissions and server-side communication.
- Custom Cell Formatting: Provides tools for creating custom cell formatters to display data in a visually appealing and informative way.
- Event Handling Shortcuts: Offers convenient methods for attaching event handlers to jqGrid events, such as row selections, cell edits, and grid loading.
- Accessibility Enhancements: Includes features to improve the accessibility of jqGrid for users with disabilities.
Installation
npm install jqgrid_utilsUsage
Include the Library:
Add the following
<script>tag to your HTML file, ensuring it's placed after jQuery and free jqGrid are included:<script src="../node_modules/jqgrid_utils/dist/jqgrid_utils.js"></script>Instantiate the
Jqgrid_utilsClass:Create an instance of the
Jqgrid_utilsclass in your JavaScript code:let jqu = new Jqgrid_utils();Use the Utility Functions:
Call the various methods of the
jquobject to perform tasks related to jqGrid. See the examples below and the API documentation for details on available functions.
Examples
Here are a few examples of how to use jqgrid_utils:
Basic jqGrid Initialization:
let jqu = new Jqgrid_utils(); $(document).ready(function () { $("#grid").jqGrid({ // Use jqu.getDefaultGridOptions() to get a base set of options ...jqu.getDefaultGridOptions({ url: '/data', colModel: [ { name: 'id', label: 'ID', width: 50 }, { name: 'name', label: 'Name', width: 150 }, { name: 'email', label: 'Email', width: 200 } ], caption: "My Grid" }), loadComplete: function() { // Example of using a utility function after the grid loads jqu.highlightRows("#grid"); } }); });Highlighting Rows: (Assuming you have a
highlightRowsfunction)jqu.highlightRows("#grid"); // Highlights rows in the grid with ID "grid"Formatting Dates: (Assuming you have a
formatDatefunction)let formattedDate = jqu.formatDate("2023-10-27", "MM/DD/YYYY"); // Formats the date console.log(formattedDate); // Output: 10/27/2023
API Documentation
For detailed information on all available functions and options, please refer to the API documentation:
https://github.com/myridia/jqgrid_utils/blob/main/README.md
(This README is the API documentation for now. Consider generating proper documentation with JSDoc or similar if the library grows.)
Source Code
The source code for jqgrid_utils is available on GitHub:
https://github.com/myridia/jqgrid_utils/actions
Contributing
We welcome contributions to jqgrid_utils! If you have a bug fix, a new feature, or an improvement to suggest, please follow these steps:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and commit them with clear, descriptive messages.
- Submit a pull request to the
mainbranch.
Please ensure that your code adheres to the existing coding style and includes appropriate unit tests.
License
This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the LICENSE file for details. (You'll need to create a LICENSE file in your repository.)
Future Enhancements
- More comprehensive data formatting options.
- Built-in support for common jqGrid plugins.
- Improved error handling and logging.
- More detailed documentation and examples.
- TypeScript definitions.
Support
If you encounter any issues or have questions about jqgrid_utils, please open an issue on GitHub.
Jqgrid_utils
A module for Jqgrid_utils
Jqgrid_utils
A module for Jqgrid_utils
- Jqgrid_utils
- module.exports#format_currency_on_value(col_model, edit_field, currency) ⏏
- module.exports#format_currency(col_model, edit_field, currency) ⏏
- module.exports#add_checkbox(col_model, field_name) ⏏
- module.exports#add_class(col_model, field_name, class_name) ⏏
- module.exports#_grid_substract_on() ⏏
- module.exports#grid_substract_on(grid, minuend, subtrahend, difference, no_negative) ⏏
- module.exports#_grid_ratio_on() ⏏
- module.exports#grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) ⏏
- module.exports#is_html(str) ⇒ boolean ⏏
- module.exports#_grid_sum_on() ⏏
- module.exports#grid_sum_on(grid, fields, format, exclude) ⏏
- module.exports#_grid_avg_on() ⏏
- module.exports#grid_avg_on(grid, fields) ⏏
- module.exports#_grid_percent_on() ⏏
- module.exports#grid_percent_on(grid, obj) ⏏
- module.exports#update_row_to_api(_self, api, _ids, row) ⏏
- module.exports#delete_row_to_api(_self, api, rowid, _ids, data) ⏏
- module.exports#append_seperator_link_column(col_model, url, field_value, base, attr, keys) ⏏
- module.exports#add_edit(col_model) ⏏
- module.exports#add_textarea(col_model, edit_field) ⏏
- module.exports#get_col_model_from_data(obj, data, exclude, col_model) ⇒ array ⏏
- module.exports#binary_replace(cell_value, a, b) ⏏
- module.exports#_date112_to_DMY(cell_value, seperator) ⏏
- module.exports#date112_to_DMY(col_model, edit_field, seperator) ⏏
- module.exports#add_formatter(col_model, edit_field, formatter) ⏏
- module.exports#natural_sort(col_model, column_name) ⇒ array ⏏
- module.exports#add_html_formatter(col_model, edit_field, html) ⇒ array ⏏
- module.exports#add_ok_button(col_model, fields) ⇒ array ⏏
- module.exports#get_filled_cell_table_data(_grid, fields) ⇒ array ⏏
- module.exports#get_filled_cell_data(_grid, fields) ⇒ object ⏏
- module.exports#set_link(col_model, edit_field, url) ⇒ object ⏏
- module.exports#hide_all_columns_except(col_model, fields) ⇒ object ⏏
- module.exports#hide_column(col_model, field) ⇒ object ⏏
- module.exports#s_grid_set_caption(_grid, data) ⏏
- module.exports#grid_set_caption(_grid, data) ⏏
- module.exports#s_resize_saved_cell_width(col_model, page, grid) ⏏
- module.exports#resize_saved_cell_width(col_model, page, grid) ⏏
- module.exports#resize_cell(the, column, not) ⏏
- module.exports#upsert_row(row, url, req) ⇒ object ⏏
- module.exports#insert_row(row, url) ⇒ object ⏏
- module.exports#update_row(row, url, req) ⇒ object ⏏
- module.exports#delete_row(_id, url) ⇒ object ⏏
- module.exports#adelete_api(url, json) ⇒ object ⏏
- module.exports#post_json(url, data) ⇒ object ⏏
- module.exports#put_json(url, data) ⇒ object ⏏
- module.exports#s_hide_del_icon() ⏏
- module.exports#hide_del_icon() ⏏
- module.exports#add_link_details_csv(col_model, url, edit_field, attr, keys, format, seperator) ⏏
- module.exports#compare(obj, column1, column2, css_class) ⏏
- module.exports#compare_smaller(obj, column1, column2, css_class) ⏏
- module.exports#compare_bigger(obj, column1, column2, css_class) ⏏
- module.exports#set_styles(obj, style_column) ⏏
- module.exports#set_classes(grid_id) ⏏
- module.exports#add_link_details(col_model, url, edit_field, attr, keys) ⏏
- module.exports#add_link_details_separator(col_model, url, edit_field, attr, keys) ⏏
- module.exports#add_link_separator(col_model, url, edit_field, fields) ⏏
- module.exports#_format_number_with_commas(number) ⏏
- module.exports#__cell_format(cell_value, format) ⏏
- module.exports#subgrid(_id, id, url, col_model, caption) ⏏
- module.exports#add_image(col_model, edit_field, size, link) ⏏
- module.exports#set_filter(grid, data, fx, append_to) ⏏
- module.exports#_filter() ⏏
module.exports#format_currency_on_value(col_model, edit_field, currency) ⏏
Format a number into a currency if have value, otherwise return empty
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | col_model of the grid | | edit_field | string | | name of column to be formatter | | currency | string | "$" | currency symbol, default is $ |
Example
var jqu = new Jqgrid_utils();
let _data = await jqu.format_currency(this,'my_field','$');
console.log(_data);module.exports#format_currency(col_model, edit_field, currency) ⏏
Format a number into a currency
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | col_model of the grid | | edit_field | string | | name of column to be formatter | | currency | string | "$" | currency symbol, default is $ |
Example
var jqu = new Jqgrid_utils();
let _data = await jqu.format_currency(this,'my_field','$');
console.log(_data);module.exports#add_checkbox(col_model, field_name) ⏏
Add a Checkbox to the Model
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | array | grid col_model | | field_name | string | column_name |
Example
var jqu = new Jqgrid_utils();
ol_model = await jqu.add_checkbox(col_model, "closed");module.exports#add_class(col_model, field_name, class_name) ⏏
Add a Class to the Model
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | array | grid col_model | | field_name | string | column_name | | class_name | string | class_name |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_class(col_model,field_name,class_name)module.exports#_grid_substract_on() ⏏
Syncron Alias grid_sum_on
Kind: Exported function
module.exports#grid_substract_on(grid, minuend, subtrahend, difference, no_negative) ⏏
Sum the columns values together
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | grid | object | | Grid Object (required) | | minuend | array | | string array list of field_names used as minuend(number from which the other number is subtracted) | | subtrahend | array | | string array list of field_names used as subtrahend(number which is to be subtracted from the minuend) | | difference | string | | string field name for the difference(number which is to be subtracted from the minuend) | | no_negative | bolen | false | true or 1 to not show negative numbers |
Example
var jqu = new Jqgrid_utils({page:page});
gridComplete: function () {
jqu._jqu._grid_sum_on(this, [
"qty_icollect",
"qty_ordered",
"need_for_qty_ordered",
"wait_icollect",
]);
},module.exports#_grid_ratio_on() ⏏
Syncron Alias grid_ratio_on
Kind: Exported function
module.exports#grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) ⏏
Get the ratio the columns values together
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | grid | object | Grid Object (required) | | fraction_col | string | Column/Field Name for value 1 | | denominator_col | string | Column/Field Name for value 2 | | ratio_col | string | Column/Field Name to the set the target ratio |
Example
var jqu = new Jqgrid_utils({page:page});
gridComplete: function()
{
jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
},module.exports#is_html(str) ⇒ boolean ⏏
Check if the string is html
Kind: Exported function
Returns: boolean - - true or false
| Param | Type | Description | | --- | --- | --- | | str | string | String of any kind |
module.exports#_grid_sum_on() ⏏
Syncron Alias grid_sum_on
Kind: Exported function
module.exports#grid_sum_on(grid, fields, format, exclude) ⏏
Sum the columns values together
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | grid | object | Grid Object (required) | | fields | string | Column/Field Name to sum | | format | string | format, currency sign | | exclude | array | exclude, array of column field key:value object, example [{"user": "foo"}] - it excludes user with value foo |
Example
var jqu = new Jqgrid_utils({page:page});
gridComplete: function () {
jqu._jqu._grid_sum_on(this, [
"qty_icollect",
"qty_ordered",
"need_for_qty_ordered",
"wait_icollect",
]
"$",
[{user:"foo",country:"None"}]
);
},module.exports#_grid_avg_on() ⏏
Syncron Alias grid_avg_on
Kind: Exported function
module.exports#grid_avg_on(grid, fields) ⏏
Average the column values together
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | grid | object | Grid Object (required) | | fields | array | Column/Field Names to where the average of each column should be calculated |
Example
var jqu = new Jqgrid_utils({page:page});
gridComplete: function()
{
jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
},module.exports#_grid_percent_on() ⏏
Syncron Alias grid_percent_on
Kind: Exported function
module.exports#grid_percent_on(grid, obj) ⏏
Percent the columns values together
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | grid | object | Grid Object (required) | | obj | string | Column/Field Name to sum |
Example
var jqu = new Jqgrid_utils({page:page});
gridComplete: function () {
jqu._jqu._grid_sum_on(this, [
"qty_icollect",
"qty_ordered",
"need_for_qty_ordered",
"wait_icollect",
]);
},module.exports#update_row_to_api(_self, api, _ids, row) ⏏
Takes the updated columns data and send it to your API post server loadComplete: async function() for the old record needs to be called, see example !
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | _self | object | Grid Object (required) | | api | string | API URL like https://foo.com (required) | | _ids | array | id list, ids from the column header (required) | | row | object | settings - extra key:value to send to your server |
Example
var jqu = new Jqgrid_utils({page:page});
....},
loadComplete: async function()
{
$grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
},
afterSetRow: async function(row)
{
const _api = await get_api_url('sapir');
const api = _api + '/column2';
let info = {"msg":"failed"};
var jqu = new Jqgrid_utils();
info = await jqu.update_row_to_api($grid, api,['id'],row,{server : '232',db : 'sl_h',table : 'kpi',});
for(let i in info)
{
log.info(info[i]);
}
},module.exports#delete_row_to_api(_self, api, rowid, _ids, data) ⏏
After Delete a Grid Row send to and DELETE REST Request You need to define loadComplete and afterDelRow The Grid data needs to be saved as record within loadComplete
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | _self | object | Grid Object (required) | | api | string | API URL like https://foo.com (required) | | rowid | string | the row id value from afterDelRow (required) | | _ids | array | id list, ids from the column header colmodel (required) | | data | object | settings - extra key:value to send to your server |
Example
loadComplete: async function()
{
$grid.jqGrid('setGridParam',{record_data:$grid.jqGrid("getGridParam").data});
},
afterDelRow: async function(rowid)
{
const _api = await get_api_url('sapir');
const api = _api + '/column2';
let info = {"msg":"failed"};
var jqu = new Jqgrid_utils();
info = await jqu.delete_row_to_api($grid,api,rowid,['id'],{
server : '232',
db : 'sl_h',
table : 'kpi',
operator: 'delete',
});
log.info(JSON.parse(info).msg);
},module.exports#append_seperator_link_column(col_model, url, field_value, base, attr, keys) ⏏
Append and sperator based link column to the end of a row
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | url | string | URL string | | field_value | string | field value - the visible text of the anchor | | base | object | base row key value - like {"name":'wiki','label':"Wiki"} | | attr | string | URL Attributes | | keys | object | keys and fields value to use |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.append_seperator_link_column(col_model, 'http://wiki.foo.com/index.php' ,'Wiki',{"name":'wiki','label':"Wiki","width":"65px","align":"center"} ,'target="_blank"',{"report_central":"name"});module.exports#add_edit(col_model) ⏏
add textarea
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | object | edittype like |
Example
let col_model = JSON.parse(await aget_api(url + "/model"));
col_model = await jqu.add_edit(col_model, 'mon',{ edittype:'textarea', editoptions:{rows:6,cols:100} });
see for other inputfields:
http://www.trirand.com/blog/phpjqgrid/doc/_2v80w6oam.htmmodule.exports#add_textarea(col_model, edit_field) ⏏
add textarea
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | string | edit_filed | | edit_field | string | style of the textaread |
Example
let col_model = JSON.parse(await aget_api(url + "/model"));
col_model = await jqu.add_textarea(col_model, 'worker','style="width:100%;height:100px"');module.exports#get_col_model_from_data(obj, data, exclude, col_model) ⇒ array ⏏
Get basic colModel data from raw data
Kind: Exported function
Returns: array - - col_model
| Param | Type | Description | | --- | --- | --- | | obj | array | grid object | | data | array | raw data object from loadComplete | | exclude | array | list of columns to exclude (optional) | | col_model | array | existing colModel (optional) |
Example
var jqu = new Jqgrid_utils();
,loadComplete: async function(data)
{
let col_model = jQuery(this).jqGrid('getGridParam',"colModel");
const new_col_model= await update_col_model(this, data, ['id','cust_qty','waiting_supplier_orders','waiting_assemblies','pending_components','pending_customer_order',col_model);
jQuery(this).jqGrid('setGridParam',{colModel:new_col_model});
},module.exports#binary_replace(cell_value, a, b) ⏏
Replace a Binaery 0 or 1 to other given value
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | cell_value | string | | cell value | | a | string | "zero" | string replacement for 0 | | b | string | "one" | string replacement for 1 |
Example
var jqu = new Jqgrid_utils();
let _data = jqu.binery_replace(0,'zero','one');
or for column formatter
download_formatter:"var jqu = new Jqgrid_utils();jqu.binary_replace({0},'zero','one')"});module.exports#_date112_to_DMY(cell_value, seperator) ⏏
Convert a 112 date string to a DMY format with sepertaor - sync function
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | cell_value | string | | date string | | seperator | string | "/" | seperator used |
Example
var jqu = new Jqgrid_utils();
let _data = jqu._date112_to_DMY('20220104','/');
console.log(_data);module.exports#date112_to_DMY(col_model, edit_field, seperator) ⏏
Convert a 112 date to a DMY format with sepertaor
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | col_model of the grid | | edit_field | string | | name of the date 112 column what should get converted | | seperator | string | "/" | seperator used |
Example
var jqu = new Jqgrid_utils();
let _data = await jqu.date112_to_DMY(this,'field','/');
console.log(_data);module.exports#add_formatter(col_model, edit_field, formatter) ⏏
Add Formatter
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | array | grid col_model | | edit_field | string | string columns names what will be formatted | | formatter | object | formatter object like { formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }} |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_formatter(col_model,'select',{ formatter: "select", formatoptions: {value: "1:ok;0:fail", defaultValue: "1" }})module.exports#natural_sort(col_model, column_name) ⇒ array ⏏
Natural Sort Column
Kind: Exported function
Returns: array - - col_model
| Param | Type | Description | | --- | --- | --- | | col_model | array | grid col_model | | column_name | string | string columns names for natural sorting |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.natural_sort(col_model,'colunmename');module.exports#add_html_formatter(col_model, edit_field, html) ⇒ array ⏏
Add HTML Formatter
Kind: Exported function
Returns: array - - col_model
| Param | Type | Description | | --- | --- | --- | | col_model | array | grid col_model | | edit_field | string | string columns names what will be converted to ok buttons | | html | string | html tag code |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_html_formatter(col_model,'process',"<button tabindex='0' class='cellbtn' type='button'>Process</button>");module.exports#add_ok_button(col_model, fields) ⇒ array ⏏
Add an OK Button
Kind: Exported function
Returns: array - - col_model
| Param | Type | Description | | --- | --- | --- | | col_model | array | grid col_model | | fields | array | list of columns names what will be converted to ok buttons |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_ok_button(col_model, ['checked']);module.exports#get_filled_cell_table_data(_grid, fields) ⇒ array ⏏
Get the filled cell data
Kind: Exported function
Returns: array - - table array
| Param | Type | Description | | --- | --- | --- | | _grid | object | the grid object or its name | | fields | array | list of columns names what will be collected |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.get_filled_cell_table_dat("#gridname","fieldname");module.exports#get_filled_cell_data(_grid, fields) ⇒ object ⏏
Get the filled cell data
Kind: Exported function
Returns: object - - json object of the colleted fields
| Param | Type | Description | | --- | --- | --- | | _grid | object | the grid object or its name | | fields | array | list of columns names what will be collected |
Example
var jqu = new Jqgrid_utils();
let _data = await jqu.get_filled_cell_data(this,["P-","bulk","wholesale"]);module.exports#set_link(col_model, edit_field, url) ⇒ object ⏏
Add an URL from the data to a specific cell/column
Kind: Exported function
Returns: object - https://foo.bar.com/av0_code/bar
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | edit_field | string | name of the column what should get convert to the url | | url | string | the used url of the data |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.set_link(col_model,'field_get_url','field_with_the_url','target="blank"');
console.log(_data);module.exports#hide_all_columns_except(col_model, fields) ⇒ object ⏏
Hide all columns execpt column
Kind: Exported function
Returns: object - col_model
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | fields | array | array of names to not to hide |
Example
col_model = await jqu.hide_all_columns_except(col_model,['supplier','customer']);module.exports#hide_column(col_model, field) ⇒ object ⏏
Hide a col_model column before load the grid
Kind: Exported function
Returns: object - col_model
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | field | string | name of the column to hide |
Example
col_model = await jqu.hide_column(col_model,'wholesale');
col_model = await jqu.hide_column(col_model,'wholesale_formula');module.exports#s_grid_set_caption(_grid, data) ⏏
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | _grid | object | gridobject; | | data | object | grid data (optional); |
Example
var jqu = new Jqgrid_utils();
loadComplete: function(){
jqu.grid_set_caption(this);
},module.exports#grid_set_caption(_grid, data) ⏏
Adding the row count number to the caption
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | _grid | object | gridobject; | | data | object | grid data (optional); |
Example
var jqu = new Jqgrid_utils();
loadComplete: function(){
await jqu.grid_set_caption(this);
},module.exports#s_resize_saved_cell_width(col_model, page, grid) ⏏
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | the col_model of the grid | | page | string | false | the name of the page(optional) | | grid | object | false | the grid objec(optional) |
Example
col_model = await jqu.resize_saved_cell_width(col_model);module.exports#resize_saved_cell_width(col_model, page, grid) ⏏
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | the col_model of the grid | | page | string | false | the name of the page(optional) | | grid | object | false | the grid objec(optional) |
Example
col_model = await jqu.resize_saved_cell_width(col_model);module.exports#resize_cell(the, column, not) ⏏
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | the | string | width of the resized column | | column | string | number what get resized | | not | string | in use yet |
Example
var jqu = new Jqgrid_utils({page:'mypage'});
resizeStop: jqu.resize_cell,module.exports#upsert_row(row, url, req) ⇒ object ⏏
Upsert(insert or update) from the grid to an API
Kind: Exported function
Returns: object - {update: 'ok'} or {update: 'failed'}
| Param | Type | Description | | --- | --- | --- | | row | object | row object | | url | string | url of the API | | req | string | data oject |
Example
var jqu = new Jqgrid_utils();
afterSetRow: async function(row)
{
let r = await jqu.upsert_row(row, 'http://api.com',{'key':'value'});
console.log(r);
},module.exports#insert_row(row, url) ⇒ object ⏏
Insert from the grid to an API used by the upsert_row function
Kind: Exported function
Returns: object - Object from the the API like {update: 'ok'} or {update: 'failed'}
| Param | Type | Description | | --- | --- | --- | | row | object | row object | | url | string | URL of the API |
Example
var jqu = new Jqgrid_utils();
afterSetRow: async function(row)
{
let r = await jqu.insert_row(row, 'http://api.com');
console.log(r);
},module.exports#update_row(row, url, req) ⇒ object ⏏
Update from the grid to an API used by the upsert_row function
Kind: Exported function
Returns: object - Object from the the API like {update: 'ok'} or {update: 'failed'}
| Param | Type | Description | | --- | --- | --- | | row | object | row object | | url | string | url of the API | | req | string | data oject |
Example
var jqu = new Jqgrid_utils();
afterSetRow: async function(row)
{
let r = await jqu.update_row(row, 'http://api.com',{'key':value});
console.log(r);
},module.exports#delete_row(_id, url) ⇒ object ⏏
Delete from the grid to an API
Kind: Exported function
Returns: object - @returns {object} Object from the the API like {delete: 'ok'} or {delete: 'failed'}
| Param | Type | Description | | --- | --- | --- | | _id | string | row id | | url | string | url of the API |
Example
var jqu = new Jqgrid_utils();
afterDelRow: async function(row)
{
const r = await jqu.delete_row('id', 'http://api.com');
console.log(r + ' : ' + row + ' - from API');
},module.exports#adelete_api(url, json) ⇒ object ⏏
Async Delete request used by function delete_row
Kind: Exported function
Returns: object - @returns {object} Object from the the API like {delete: 'ok'} or {delete: 'failed'}
| Param | Type | Default | Description | | --- | --- | --- | --- | | url | string | | url of the API | | json | boalan | false | header should be json type? default form type |
Example
var jqu = new Jqgrid_utils();
afterDelRow: async function(row)
{
ret = JSON.parse(await jqu.adelete_api(url));
},module.exports#post_json(url, data) ⇒ object ⏏
Async Post request used by the update_row function
Kind: Exported function
Returns: object - @returns {object} Object from the the API like {update: 'ok'} or {update: 'failed'}
| Param | Type | Description | | --- | --- | --- | | url | string | url of the API | | data | object | json object |
Example
var jqu = new Jqgrid_utils();
ret = JSON.parse(await jqu.post_json(url,{'key':value,'key2':'value'}));module.exports#put_json(url, data) ⇒ object ⏏
Async Put request used by the insert_row function
Kind: Exported function
Returns: object - @returns {object} Object from the the API like {insert: 'ok'} or {insert: 'failed'}
| Param | Type | Description | | --- | --- | --- | | url | string | url of the API | | data | object | json object |
Example
var jqu = new Jqgrid_utils();
ret = JSON.parse(await jqu.put_json(url,{'key':value,'key2':'value2'}));module.exports#s_hide_del_icon() ⏏
Hide the del iconf rom the grid
Kind: Exported function
Example
var jqu = new Jqgrid_utils();
jqu.hide_del_icon();module.exports#hide_del_icon() ⏏
Hide the del iconf rom the grid
Kind: Exported function
Example
var jqu = new Jqgrid_utils();
await jqu.hide_del_icon();module.exports#add_link_details_csv(col_model, url, edit_field, attr, keys, format, seperator) ⏏
Convert a cell into a link/url with data from another cell and spit the value by comma - CSV
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | col_model of the grid | | url | string | | URL string | | edit_field | string | | Column/Cell to use | | attr | string | | URL Attributes | | keys | object | | keys and fields value to use | | format | object | | format info | | seperator | string | "," | seperator of the cell value to split (default is comma) |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_link_details_csv(col_model, host + '/html/report.html' , 'tags','target="_blank"',{"tags":"tags"},',');module.exports#compare(obj, column1, column2, css_class) ⏏
Compare 2 columns and give them a style class when they have different content http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | obj | object | grid object | | column1 | string | first column | | column2 | string | second column | | css_class | string | css class name |
Example
loadComplete: async function()
{
await jqu.compare(this,'first_column','second_column','redlight');
}module.exports#compare_smaller(obj, column1, column2, css_class) ⏏
Compare 2 columns for smaller and give them a style class http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | obj | object | grid object | | column1 | string | first column | | column2 | string | second column | | css_class | string | css class name |
Example
loadComplete: async function()
{
await jqu.compare(this,'first_column','second_column','redlight');
}module.exports#compare_bigger(obj, column1, column2, css_class) ⏏
Compare 2 columns for bigger and give them a style class http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | obj | object | grid object | | column1 | string | first column | | column2 | string | second column | | css_class | string | css class name |
Example
loadComplete: async function()
{
await jqu.compare(this,'first_column','second_column','redlight');
}module.exports#set_styles(obj, style_column) ⏏
Set styles to individual cells, what are defined in a dedicated column
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | object | | grid object | | style_column | string | "styles" | name of the column what includes the style values what need to be in a strinify json format |
Example
var jqu = new Jqgrid_utils();
loadComplete: async function() {
await jqu.set_styles(this);
},module.exports#set_classes(grid_id) ⏏
Set a class to a row, what must be defined in a dedicated column called row.class Once the grid is loaded, the functions adds extra class to the row element
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | grid_id | object | grid id like #grid |
Example
var jqu = new Jqgrid_utils();
loadComplete: async function() {
await jqu.set_classes("#grid");
},module.exports#add_link_details(col_model, url, edit_field, attr, keys) ⏏
Convert a cell into a link/url with data from another cell
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | url | string | URL string | | edit_field | string | Column/Cell to use | | attr | string | URL Attributes | | keys | object | keys and fields value to use |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_link_details(col_model,'http://foo.bar' , 'style','target="_blank"',{'key':'style'});
col_model = await jqu.add_link_details(col_model, host + '/html/table_size.html' , 'database','target="_blank"',{"database":"database","server":"server"});module.exports#add_link_details_separator(col_model, url, edit_field, attr, keys) ⏏
Convert a cell into seperated based link/url like https://foo.bar.com/field/value/field/value
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | url | string | URL string | | edit_field | string | Column/Cell to use | | attr | string | URL Attributes | | keys | object | keys and fields value to use |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_link_details_separator(col_model, url1 , 'style','target="_blank"',{"pricelist":"pricelist","style":"style"});
col_model = await jqu.add_link_details_separator(col_model, 'https://foo.com' , 'target_column','target="_blank"',{"mykey":"myval"});module.exports#add_link_separator(col_model, url, edit_field, fields) ⏏
Convert a cell into seperated based link/url include parameter based url like https://foo.bar.com/field.html?k=v
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | col_model | object | col_model of the grid | | url | string | URL string | | edit_field | array | array of dict | | fields | string | URL Attributes |
Example
var jqu = new Jqgrid_utils();
col_model = await jqu.add_link_separator(col_model, host + '/html' , 'style',[
{
'field':'pricelist',
'extension':'.html',
'fields':{'style':'style'}
}
]);
//other example
col_model = await jqu.add_link_separator(col_model, 'https://wiki.salamander-jewelry.net/index.php/grid_loss' , 'e',[{'field':'e'}],'target="_blank"');module.exports#_format_number_with_commas(number) ⏏
Private Function
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | number | string | number to add comma |
module.exports#__cell_format(cell_value, format) ⏏
Private Function
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | cell_value | object | cell_value | | format | string | format_ok or $ sign |
module.exports#subgrid(_id, id, url, col_model, caption) ⏏
Kind: Exported function
| Param | Type | Description | | --- | --- | --- | | _id | string | row_id | | id | string | data id | | url | string | url to request | | col_model | object | col_model for the table | | caption | string | Add to the caption of the subgrid |
Example
subGrid: true,
,subGridRowExpanded: async function(_id, id) {
let data_url2 = api + '/process_locations?f=data&process=';
let col_model_url2 = api + '/process_locations?f=col_model';
let col_model2 = JSON.parse(await vwu.aget_api(col_model_url2));
await jqu.subgrid(_id, id, data_url2, col_model2,'Locations for Process');
let data_url = api + '/process_styles?f=data&process=';
let col_model_url = api + '/process_styles?f=col_model';
let col_model = JSON.parse(await vwu.aget_api(col_model_url));
await jqu.subgrid(_id, id, data_url, col_model,'Styles for Process');
},
or
subGrid: true,
subGridRowExpanded: async function(_id, id) {
let row_data = jQuery(this).jqGrid ('getRowData', id);
let param={f:'data','style':row_data['style'],pricelist:'P-TENENGR1'};
let data_url = api + '/order_ln';
data_url = await add_parameters(data_url, param);
let col_model_url2 = api + '/order_ln?f=col_model';
let col_model2 = JSON.parse(await vwu.aget_api(col_model_url2));
await jqu.subgrid(_id, false, data_url, col_model2,'Order Lines for ' + row_data['style']);
},module.exports#add_image(col_model, edit_field, size, link) ⏏
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | col_model | object | | col_model for the grid | | edit_field | string | | field what include the image/picture href path like http://mypicture.png | | size | int | | size of the picture | | link | bolen | false | image path should be a link |
Example
col_model = await jqu.add_image(col_model, image_field, 60, false);module.exports#set_filter(grid, data, fx, append_to) ⏏
Add a filter to the website beside the grid
Kind: Exported function
| Param | Type | Default | Description | | --- | --- | --- | --- | | grid | object | | grid object or grid string name | | data | object | | the grid data object | | fx | object | | a dict with a array what should be filterd by the grid | | append_to | string | "#filter" | id name of the DOM oject where the filter should be appened |
Example
var jqu = new Jqgrid_utils();
var run_me_once = true;
gridComplete: async function(){
if(run_me_once)
{
await jqu.set_filter(this, data, {material:[],section:[]}, '#filter');
run_me_once = false;
}
},module.exports#_filter() ⏏
private function of set_filter
Kind: Exported function
