Calx comes with several API that can be invoked using this syntax $('selector').calx('method')
,
here is list of available method that can be accessed by jQuery Calx:
calculate
$('selector').calx('calculate')
This method is used to trigger calculation process on the sheet related to the selected element,
which is useful when you configure jQuery Calx withautoCalculate : false
or working
with large sheet where the calculation process take some times to finish and need to be triggerred
manually.destroy
$('selector').calx('destroy')
This method is used to destroy sheet object related to the selected element, any formula referenced
to the cells inside this sheet will become invalid, and may result in wrong calculation.evaluate
$('selector').calx('evaluate', formula)
This method is used to evaluate formula against the current selected sheet, all cell addresses and
variables are referenced to the current sheet.You can do something like :
$('selector').calx('evaluate', 'SUM(A1:A5)')
and jQuery Calx will return the result of the formula.
setValue
$('selector').calx('setValue', cellAddress, cellValue)
This method is used to set the value into specific cell, it will recalculate the sheet if the autoCalculate is enabled.
$('selector').calx('setValue', 'A1', 100)
getCell
$('selector').calx('getCell', cellAddress)
This method is used to retrieve specified cell object of the selected sheet.
Please refer to Cell API for detailed documentation about cell object.getSheet
$('selector').calx('getSheet')
This method is used to retreive sheet object related to the selected element.
Please refer to Sheet API for detailed documentation about sheet object.getUtility
$('selector').calx('getUtility')
This method is used to retrieve utility object when you need some help with the cell or cell range.
refresh
$('selector').calx('refresh')
This method is used to force jQuery Calx to rebuild the sheet of the selected element.
It will destroy the cell registry and rebuild it from scratch.registerFunction
$('selector').calx('registerFunction', FUNCTION_NAME, function_definition
[, override])This method is used to register new function and can be used in
data-formula
attribute.
The parameters is described as below:- FUNCTION_NAME
the function name such as SUM, AVG, etc, must be uppercase letter - function_definition
the function definition define how the function should behavefunction(){ /** bla bla bla **/ }
,
jQuery Calx will pass the sheet object as the context, so you can access all the sheet API via
this
keyword. - override
the optional override flag, could be true or false to indicate if new function should override the
original one or not. If true, the built in function will be overrided, default value is false.
$('selector').calx('registerFunction', 'CUSTOM', function(args1, args2, ... , argsN){ //<this> keyword will be sheet object where the current formula is evaluated //if data-formula look like CUSTOM(A1), the value of A1 will be passed as args1 //if data-formula look like CUSTOM(A1:B2), the value of args1 will be like //{A1:value, A2:value, B1:value, B2:value} //function should return calculated value to be rendered into the cell that invoke this function });
And after the function is registered, you can simply write it in the
data-formula
attribute:
<span data-formula="CUSTOM(A1,A2,100,C1:D5)"></span>
registerVariable
$('selector').calx('registerVariable', var_name [, var_value])
This method is used to register variables to the calx, and are available to all sheet. The variable name
should be all lowercase and underscore character ([a-z_]) and the value could be anything as far as the function
can handle it.$().calx('registerVariable', 'the_year_i_was_born', 1988)
Or you can define multiple variable at one time using javascript object
$().calx('registerVariable', {varname: 'value', another_var: 'another value'})
After variable is registered, you can reference it in data-formula attribute like
data-formula="CONCAT('I was born in ', the_year_i_was_born)"
Please note that there are predefined variables: true, false, and null disregard of the character is lower
case or upper case, or mix of both, which mean true, TRUE, tRue are all the same.update
$('selector').calx('update')
This method is used to update cell registry against any change in the element related to the sheet,
update
is similar torefresh
, but instead of rebuild the cell registry from
the scratch, it only add or delete cell that has been added or removed from the sheet’s element.This is useful when you are working with dynamic form where form elements are added or removed on the fly.
reset
$('selector').calx('reset')
This method is used to reset the form inside the sheet element to its original state.
- FUNCTION_NAME
Hi Ikshan,
First off, thank you for this wonderful library, and I have developed a rather impressive prototype using this library, however I am having a strange problem and with a very simple formula.
When I add a formula to check for blank with an IF condition, I get the false value instead of the true, even though the field is blank, but when I type in it and then clear it, the function performs properly.
My formula is IF(A14=””, 0, 3), this returns 3 by default even though the textbox is blank, but if i enter in it and then clear it, it returns 0 as is expected. Please guide what I may be missing here.
Elvis F.
I rolled back to 2.2.7 and all is well.
Please note, this is broken in 2.2.8, tested it even on the sample pages, as well as my own application using this version.
Thanks Ikhsan.
Halo Mas Iksan,
Bagaimana cara menambah tombol reset pada Calx ini yah? Saya menggunakan Calx 2.2.7. Mohon petunjuknya agar saya bisa me-reset semua input dan outputnya.
Maaf mas, baru bales, gak tau kenapa gak ada email masuk kalo ada komen
kalau mau reset bisa coba pake
$('#form').reset();
$('#form').calx('update');
I have used json and table html method to display a list of result.
However, I found that I couldn’t use onChange action to get the updated value for those input value.
Could you suggest the way so that I can get the updated json after users clicked “Submit” button.
Thanks!
Hi AL,
I am a bit unclear about what you want to achieve, but you can get the each cell value by iterating through cells object
Hi! I am a bit lost right now (and not blessed with great jquery-skills), so it would be great if you could help me out:
I need the value of cell for another function in my script. The value of the input “qwKLED” should be used in a function (which is searching an array).
So this is how my #qwKLED looks like:
And this is how a part of my function (outside of calcx) works:
Does this make sense at all to you or am I doing it completely wrong? I also played around with “getcell” which did not work…
Thanks in advance!
Aline
Hi Aline,
Which version if jQuery calx do you use?
Hello!
Am I able to have both input and output in a cell?
Can I manually add a number to it while, if I don’t, have it use a formula to display something from another cell?
Hello!
Is the following possible:
I have a data-formula for a cell, but would like to also be able to input a number in that cell independent of the formula.
Alternately, I have a data-cell with an input ability, but would like to have it calculate a formula from the above input.
Am I able to do this?
Hi Erik,
unfortunately cell with data-formula will be readonly, every time it lose focus/blurred, the value will be replaced by the formula result, but you can do some trick, while user input value to the field, remove the formula of that cell.
regards
Ikhsan
Hello ikhsan,
Thanks it works fine !
Yves-Andre
Hello ikhsan,
would require your help regarding reproducing of the registerVariable,
i cant get it work as i keep on getting #UNDEFINED_VARIABLE! error. cant figure out wether if its coming from jquery or init config.
Hi Andre,
try to add
true
as the fourth parameter, it will tell calx to register variable as global and available on all sheetmeanwhile, I’ll try to fix the registerVariable for each sheet
regards
Ikhsan
Hi Andre,
I just released an update to fix registerVariable behavior, you can download it from github.
Regards
Ikhsan
Hi…I need some help with registerVariable.
I am not sure what should be placed in “value”.
Thanks,
Jeff
Hi Jeff,
the value should be in primitive type or function that return primitive type, if it a complex type like object or array, the function or formula should be able to handle those kind of data.
for example, basic math operation can only handle primitive data like integer or string
If the variable is dynamic, or based on another form value, or cell value, you can use function that return its value
Thank you! Getting it closer to work now.
Love the script!
Jeff