Jump to content

Using two tables (\IPS\Helpers\Table\Db) on the same page


Jornik

Recommended Posts

Hi,

i have problems using two tables with sort options (\IPS\Helpers\Table\Db) on same page, both tables are created in same controller in function manage() function.

Each table has some common columns (name) and some different columns.

If i try to use sort for the 'name' column, it sorts both tables, if i try to use sort for column that only exists in one of these tables, i get an exception.

Is there any way i could 'distinguish' for what table i am using sort?

Link to comment
Share on other sites

  • 4 months later...

solved with

<div class='ipsBox' data-baseurl='{$table->baseUrl}' data-resort='{$table->resortKey}'{{if isset($table->baseUrl->queryString['orient'])}} data-disableTableUpdates{{endif}} data-controller='core.global.core.table{{if isset($table->baseUrl->queryString['orient'])}}( widgetPoll ){{endif}}' data-tableID='elTable_{$table->uniqueId}' {{if $table->getPaginationKey() != 'page'}}data-pageParam='{$table->getPaginationKey()}'{{endif}}>
	ips.controller.mixin('widgetPoll', 'core.global.core.table', false, function () {
		this.after('updateURL', function () {
			var state = History.getState();
			if(this._initialURL != state.url)
			{
				$(window).unbind('statechange');
				History.back();
				History.Adapter.bind( window, 'statechange', _.bind( this.stateChange, this ) );
			}
		});
	});

but I don't know if effectly is the best solution @Rikki @bfarber

Link to comment
Share on other sites

  • 3 weeks later...

i have solved with

;( function($, _, undefined){
	"use strict";
	ips.controller.mixin('widgetPoll', 'core.global.core.table', false, function () {
		this.after('updateURL', function () {
			var state = History.getState();
			if(( _.isUndefined( state.data.controller ) || state.data.controller != this.controllerID ) && this._initialURL != state.url)
			{
				var self = this;
				if( self._eventListeners.length ){
					for( var i = 0; i < self._eventListeners.length; i++ ){
						var data = self._eventListeners[i];
						if( data.event == 'statechange'){
							data.elem.off( data.event );
							History.back();
							data.elem.on( data.event, data.fn );
						}
					}
				}
			 }
		});
	});
}(jQuery, _));

see previous post for html :thumbsup:

EDIT: don't work if in the same page there are other tables

Link to comment
Share on other sites

this work fine:

;( function($, _, undefined){
	"use strict";
	ips.controller.mixin('widgetPoll', 'core.global.core.table', false, function () {
		this.around('updateURL', function (fn,newParams) {
			if(this.scope.data('controller') == 'core.global.core.table( widgetPoll )')
			{
				_.extend( this._urlParams, newParams );

				var tmpStateData	= _.extend( _.clone( this._urlParams ), { controller: this.controllerID } );
				var newUrl			= this._baseURL + this._getURL();

				if( newUrl.slice(-1) == '?' ){
					newUrl = newUrl.substring( 0, newUrl.length - 1 );
				}
				this.fakeChange({
					data: tmpStateData,
					title: document.title,
					url: newUrl
				});
			}
			else
			{
				fn(newParams);
			}
		});
		this.around('stateChange', function (fn) {
			if(this.scope.data('controller') != 'core.global.core.table( widgetPoll )')
			{
				fn();
			}
		});
		/**
		 * stateChange alternative
		 *
		 * @returns {void}
		 */
		this.fakeChange = function (state) {
			// Because tables can exist alongside other widgets that manage the URL, we use the controller property
			// of the state data to identify states set by this controller only.
			// If that property doesn't exist, or if it doesn't match us, just ignore it.
			if( ( _.isUndefined( state.data.controller ) || state.data.controller != this.controllerID ) && this._initialURL != state.url ) {
				return;
			}
			/*if( state.data.bypassState ){
			 Debug.log('got state, but bypassing update');
			 //Debug.log( state );
			 //return;
			 }*/

			this._handleStateChanges( state );

			// Update data
			this._urlParams = state.data;

			// Get le new results
			// If the initial URL matches the URL for this state, then we'll load results by URL instead
			// of by object (since we don't have an object for the URL on page load)
			if( this._initialURL == state.url ){
				this._getResults( state.url );
			} else {
				this._getResults();
			}
		};
	});
}(jQuery, _));

thanks for mixin feature @Rikki

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...