akphidelt2007 Posted November 16, 2012 Share Posted November 16, 2012 Ok, I really should know this by now and I'm in a time crunch so I thought I might just ask to see if someone can point me in the right direction. So I build a table class in jquery. What I want now is to be able to handle custom functions that come about for the individuals tables I create. What I do now is have a customChange function and just use switch() to find the keyword and then run the function. But this is mighty inefficient and I have to constantly go in to the object and add the single custom instance. So for example, say on one table when the Qty is changed I want the Cost column to autocalculate and trigger a warning if the cost is above a certain value. I load up my javascript like this... $this->ajax->loadScript(" $(function() { var tbl = new Tablev2('beta'); tbl.init({'mysqlTable':'msr_data'}); tbl.ajaxDD('tid',{'text':'abbr','tbl':'budget_cats','locked':true}); tbl.ajaxDD('mid',{'text':'description','values':'mid','tbl':'modules','width':400,'numChars':2,'locked':true}); tbl.ajaxDD('sid',{'text':'description','values':'old_pav_sid','tbl':'systems','width':400,'numChars':2,'locked':true}); tbl.ajaxDD('manufacturer',{'text':'manufacturer','tbl':'msr_data','width':200,'numChars':1}); tbl.ajaxDD('line_description',{'text':'line_description','tbl':'msr_data','width':600,'numChars':2}); tbl.customChangeEvent('sid','getBudget'); tbl.customChangeEvent('per_unit_cost','calculateCost'); tbl.loadCustomMysql('tid',{'tbl':'budget_cats','matchField':'abbr','returnField':'bid','int':1}); tbl.loadCustomMysql('sid',{'tbl':'systems','matchField':'old_pav_sid','returnField':'sid','int':1}); }); "); How can I type up the function within the $this->ajax->loadScript function so I do not have to actually manipulate the object but still use the variables within the object? The way I do it now is through the tbl.customChangeEvent() and then I just write the function in the class itself. I want to be able to write the function on the script that is creating the table. Any help will be greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/270796-adding-custom-function-to-an-object/ Share on other sites More sharing options...
akphidelt2007 Posted November 16, 2012 Author Share Posted November 16, 2012 (edited) So I'm still trying to put the pieces together. Here is more of a clear picture of what I want. $this->ajax->loadScript($(function() {var tbl = new Tablev2('beta');tbl.init({'mysqlTable':'msr_data'});//right here, I want to add the ability to calculate the cost based on the unit_cost and qty//I'd like to do something like thistbl.addFunctionSomeHow(function() {$('#qty').blur(function() { alert(this.activeCell.attr('id'));}.bind(this));}.bind(this));}););[/Code] This is literally just an example of what I want to do. I want to be able to have access to this so I can manipulate the table via the custom function. Do not worry about the actual validity of the function above. I just types it up for a broad example of what I'm trying to accomplish. Thanks again. Edited November 16, 2012 by akphidelt2007 Quote Link to comment https://forums.phpfreaks.com/topic/270796-adding-custom-function-to-an-object/#findComment-1393030 Share on other sites More sharing options...
Adam Posted November 18, 2012 Share Posted November 18, 2012 Hmm you seem to be talking about "custom change events" like we know what they are? Quote Link to comment https://forums.phpfreaks.com/topic/270796-adding-custom-function-to-an-object/#findComment-1393322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.