1.26.5 • Published 2 months ago

jqgrid_utils v1.26.5

Weekly downloads
-
License
GPL-3.0-or-later
Repository
-
Last release
2 months ago

Jqgrid_utils

Convenient Functions for free jqGrid

How to install:

   npm install jqgrid_utils 

Usage:

  <script src="../node_modules/jqgrid_utils/dist/jqgrid_utils.js"></script>

Example:

  let jqu = new Jqgrid_utils();

Source: https://w3.calantas.org/free-dockers/jqgrid_utils/

Jqgrid_utils

A module for Jqgrid_utils

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

ParamTypeDescription
_selfobjectGrid Object (required)
apistringAPI URL like https://foo.com (required)
_idsarrayid list, ids from the column header (required)
rowobjectsettings - 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

ParamTypeDescription
_selfobjectGrid Object (required)
apistringAPI URL like https://foo.com (required)
rowidstringthe row id value from afterDelRow (required)
_idsarrayid list, ids from the column header colmodel (required)
dataobjectsettings - 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

ParamTypeDescription
col_modelobjectcol_model of the grid
urlstringURL string
field_valuestringfield value - the visible text of the anchor
baseobjectbase row key value - like {"name":'wiki','label':"Wiki"}
attrstringURL Attributes
keysobjectkeys 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

ParamTypeDescription
col_modelobjectedittype 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.htm

module.exports#add_textarea(col_model, edit_field) ⏏

add textarea

Kind: Exported function

ParamTypeDescription
col_modelstringedit_filed
edit_fieldstringstyle 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

ParamTypeDescription
objarraygrid object
dataarrayraw data object from loadComplete
excludearraylist of columns to exclude (optional)
col_modelarrayexisting 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

ParamTypeDefaultDescription
cell_valuestringcell value
astring"zero"string replacement for 0
bstring"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

ParamTypeDefaultDescription
cell_valuestringdate string
seperatorstring"/"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

ParamTypeDefaultDescription
col_modelobjectcol_model of the grid
edit_fieldstringname of the date 112 column what should get converted
seperatorstring"/"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

ParamTypeDescription
col_modelarraygrid col_model
edit_fieldstringstring columns names what will be formatted
formatterobjectformatter 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#add_html_formatter(col_model, edit_field, html) ⇒ array

Add HTML Formatter

Kind: Exported function
Returns: array - - col_model

ParamTypeDescription
col_modelarraygrid col_model
edit_fieldstringstring columns names what will be converted to ok buttons
htmlstringhtml 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

ParamTypeDescription
col_modelarraygrid col_model
fieldsarraylist 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

ParamTypeDescription
_gridobjectthe grid object or its name
fieldsarraylist of columns names what will be collected

Example

var jqu = new Jqgrid_utils();
col_model = await jqu.set_link(col_model,'av0_code','url_code','target="blank"');

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

ParamTypeDescription
_gridobjectthe grid object or its name
fieldsarraylist of columns names what will be collected

Example

var jqu = new Jqgrid_utils();
col_model = await jqu.set_link(col_model,'av0_code','url_code','target="blank"');

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

ParamTypeDescription
col_modelobjectcol_model of the grid
edit_fieldstringname of the column what should get convert to the url
urlstringthe used url of the data

Example

var jqu = new Jqgrid_utils();
let _data = await jqu.get_filled_cell_data(this,["P-","bulk","wholesale"]);
console.log(_data);

module.exports#hide_column(col_model, field) ⇒ object

Hide a col_model column before load the grid

Kind: Exported function
Returns: object - col_model

ParamTypeDescription
col_modelobjectcol_model of the grid
fieldstringname of the column to hide

Example

if(filter['_filter'] == 'ch_p_higher_ch_plus_10pc')
    {
      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

ParamTypeDescription
_gridobjectgridobject;
dataobjectgrid 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

ParamTypeDescription
_gridobjectgridobject;
dataobjectgrid 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

ParamTypeDefaultDescription
col_modelobjectthe col_model of the grid
pagestringfalsethe name of the page(optional)
gridobjectfalsethe 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

ParamTypeDefaultDescription
col_modelobjectthe col_model of the grid
pagestringfalsethe name of the page(optional)
gridobjectfalsethe grid objec(optional)

Example

col_model = await jqu.resize_saved_cell_width(col_model);

module.exports#resize_cell(the, column, not) ⏏

Kind: Exported function

ParamTypeDescription
thestringwidth of the resized column
columnstringnumber what get resized
notstringin 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'}

ParamTypeDescription
rowobjectrow object
urlstringurl of the API
reqstringdata 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'}

ParamTypeDescription
rowobjectrow object
urlstringURL 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'}

ParamTypeDescription
rowobjectrow object
urlstringurl of the API
reqstringdata 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'}

ParamTypeDescription
_idstringrow id
urlstringurl 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'}

ParamTypeDefaultDescription
urlstringurl of the API
jsonboalanfalseheader 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'}

ParamTypeDescription
urlstringurl of the API
dataobjectjson 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'}

ParamTypeDescription
urlstringurl of the API
dataobjectjson 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

ParamTypeDefaultDescription
col_modelobjectcol_model of the grid
urlstringURL string
edit_fieldstringColumn/Cell to use
attrstringURL Attributes
keysobjectkeys and fields value to use
formatobjectformat info
seperatorstring","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#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

ParamTypeDescription
col_modelobjectcol_model of the grid
urlstringURL string
edit_fieldstringColumn/Cell to use
attrstringURL Attributes
keysobjectkeys 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

ParamTypeDescription
col_modelobjectcol_model of the grid
urlstringURL string
edit_fieldstringColumn/Cell to use
attrstringURL Attributes
keysobjectkeys 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

ParamTypeDescription
col_modelobjectcol_model of the grid
urlstringURL string
edit_fieldarrayarray of dict
fieldsstringURL 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'}
        }
    ]);

module.exports#__cell_format() ⏏

Private Function

Kind: Exported function

module.exports#subgrid(_id, id, url, col_model, caption) ⏏

Kind: Exported function

ParamTypeDescription
_idstringrow_id
idstringdata id
urlstringurl to request
col_modelobjectcol_model for the table
captionstringAdd 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

ParamTypeDefaultDescription
col_modelobjectcol_model for the grid
edit_fieldstringfield what include the image/picture href path like http://mypicture.png
sizeintsize of the picture
linkbolenfalseimage path should be a link

Example

col_model = await jqu.add_image(col_model, 'image', 60, false);

module.exports#set_filter(grid, data, fx, append_to) ⏏

Add a filter to the website beside the grid

Kind: Exported function

ParamTypeDefaultDescription
gridobjectgrid object or grid string name
dataobjectthe grid data object
fxobjecta dict with a array what should be filterd by the grid
append_tostring"#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

1.26.5

2 months ago

1.26.4

3 months ago

1.26.3

6 months ago

1.26.1

7 months ago

1.26.2

7 months ago

1.25.1

9 months ago

1.26.0

8 months ago

1.25.0

10 months ago

1.24.0

12 months ago

1.23.0

12 months ago

1.22.0

12 months ago

1.21.0

1 year ago

1.20.0

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.6.0

1 year ago

1.5.6

2 years ago

1.9.1

1 year ago

1.9.0

1 year ago

1.7.0

1 year ago

1.5.5

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.2.0

2 years ago

1.2.18

2 years ago

1.2.19

2 years ago

1.2.8

2 years ago

1.1.9

2 years ago

1.2.7

2 years ago

1.1.8

2 years ago

1.2.6

2 years ago

1.1.7

2 years ago

1.3.4

2 years ago

1.2.5

2 years ago

1.1.6

2 years ago

1.3.3

2 years ago

1.2.4

2 years ago

1.3.2

2 years ago

1.2.3

2 years ago

1.3.1

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.9

2 years ago

1.2.12

2 years ago

1.2.10

2 years ago

1.2.11

2 years ago

1.2.16

2 years ago

1.2.17

2 years ago

1.2.14

2 years ago

1.2.15

2 years ago

1.1.5

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago