i trying create plugin based on this-one boilerplate
however stuck. here code.
(function ($, window, document, undefined) { var pluginname = 'reservationtablejqplugin'; function plugin(element, options) { // store reference source element this.container = element; this.$container = $(element); this.options = $.extend({}, $.fn[pluginname].defaults, options); this.init(); } plugin.prototype = { init: function () { this.$htmlbtn = '' + '<button class="btn btn-danger btn-xs btnprevweek"> geri</button> ' + '<button class="btn btn-danger btn-xs btntodayweek">bugun</button>' + ' <button class="btn btn-danger btn-xs btnnextweek">ileri</button>'; this.$container.append(this.$htmlbtn).append(this._rendertable()); this.$tbody = this.$container.find('table').addclass("table-bordered table-responsive table-condensed"); this.$btnmenus = $('.btnmenu'); this.$btnnextclickevent = $('.btnnextweek'); //i binding clcick events here this._btnclickevents(this.$tbody,this._appendtable()); }, destroy: function () { // remove attached data plugin this.$container.empty(); this.$container.removedata(); this.$btnnextclickevent.off('.' + pluginname); this.$btnmenus.off('.' + pluginname); }, _appendtable :function() { this.$tbody.append(this._rendertable()); }, _rendertable: function () { return (this._renderheader() + this._rendercontent()); }, _rendercontent: function () { }, _renderheader: function () { }, _getdata: function () { }, _btnclickevents: function (that,fnc) { var fncx = fnc; this.$btnmenus.on('click.' + pluginname, function () { alert('working'); }); this.$btnnextclickevent.on('click.' + pluginname,"button", function () { that.empty(); fncx(); //here givea me error,saying this__rendertable not found. //also that.empty(); functon not clear html element }); } }; $.fn[pluginname] = function (options) { var args = arguments; if (options === undefined || typeof options === 'object') { // creates new plugin instance, each selected element, , // stores reference withint element's data return this.each(function () { if (!$.data(this, 'plugin_' + pluginname)) { $.data(this, 'plugin_' + pluginname, new plugin(this, options)); } }); } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { // call public pluguin method (not starting underscore) each // selected element. if (array.prototype.slice.call(args, 1).length == 0 && $.inarray(options, $.fn[pluginname].getters) != -1) { // if user not pass arguments , method allows // work getter break chainability can return value // instead element reference. var instance = $.data(this[0], 'plugin_' + pluginname); return instance[options].apply(instance, array.prototype.slice.call(args, 1)); } else { // invoke speficied method on each selected element return this.each(function () { var instance = $.data(this, 'plugin_' + pluginname); if (instance instanceof plugin && typeof instance[options] === 'function') { instance[options].apply(instance, array.prototype.slice.call(args, 1)); } }); } } }; /** * default options */ $.fn[pluginname].defaults = { defaultoption: "i'm default option", url: "reservationpage/index", searchid: 5, starthour: 6, weeks: [], tablecss: {} }; })(jquery, window, document); my problem mention inside code, this.$btnnextclickevent not work , gives me , error "this._rendertable not found". wanna is, when btnnextclick button clear html in table , add new datas table.
Comments
Post a Comment