working on it ...

Filters

Explore Public Snippets

Sort by

Found 805 snippets matching: pagination

    public by NassimB  1430  3  5  0

    codeigniter-pagination-url-with-get-parameters

    <?
    $this->load->library('pagination');
    		
    $item_per_page = 48;
    $total_rows = //query here for total num of items from model
    	
    // thanks to Aurel for the trick see http://stackoverflow.com/questions/5384644/codeigniter-pagination-url-with-get-parameters
    if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
    	
    $config['base_url']  = base_url().'/controller/method/';
    $config['first_url'] = $config['base_url'].'0?'.http_build_query($_GET);
    	
    $config['per_page']  = $item_per_page;
    $config['total_rows'] = $total_rows; 
    		
    $this->pagination->initialize($config);
    $data['pagination'] =  $this->pagination->create_links();
    	
    $offset = $this->uri->segment(3);
    if(!$offset) $offset = 0;
    $data['result'] = // query with offset and limit ($item_per_page)
    	
    //call view
    $this->load->view("view",$data)
    

    public by olivedev  53  0  3  0

    Creating Pagination in Laravel

    View file for Laravel Pagination (https://www.cloudways.com/blog/vue-pagination-in-laravel/ ) using vuejs
    <<!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Users Data</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="{{ asset('css/app.css') }}" rel="stylesheet" />
    </head>
    <body>
    <div class="container">
    <table class="table table-striped">
    <thead>
    <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Email</th>
    </tr>
    </thead>
    <tbody>
    @foreach($employees as $emp)
    <tr>
    <td>{{ $emp->id }}</td>
    <td>{{ $emp->name }}</td>
    <td>{{ $emp->email }}</td>
    </tr>
    @endforeach
    </tbody>
    </table>
    </div>
    </body>
    </html>

    public by Tim Kinnane  217  0  3  0

    Take a WPDB query result and display it as a table, with headers from data keys. Creates demo menu page to show example table. #wordpress Basic example for previewing results, handy for debugging etc, but doesn't provide much validation, sorting, pagin...

    Take a WPDB query result and display it as a table, with headers from data keys. Creates demo menu page to show example table. #wordpress Basic example for previewing results, handy for debugging etc, but doesn't provide much validation, sorting, pagination etc.: database_table_example.php
    <?php
    
    /**
     * Take a WPDB query result and display it as a table, with headers from data keys.
     * This example only works with ARRAY_A type result from $wpdb query.
     * @param  array                $db_data Result from $wpdb query
     * @return bool                          Success, outputs table HTML
     * @author Tim Kinnane <tim@nestedcode.com>
     * @link   http://nestedcode.com
     */
    function data_table( $db_data ) {
    	if ( !is_array( $db_data) || empty( $db_data ) ) return false;
    
    	// Get the table header cells by formatting first row's keys
    	$header_vals = array();
    	$keys = array_keys( $db_data[0] );
    	foreach ($keys as $row_key) {
    		$header_vals[] = ucwords( str_replace( '_', ' ', $row_key ) ); // capitalise and convert underscores to spaces
    	}
    	$header = "<thead><tr><th>" . join( '</th><th>', $header_vals ) . "</th></tr></thead>";
    
    	// Make the data rows
    	$rows = array();
    	foreach ( $db_data as $row ) {
    		$row_vals = array();
    		foreach ($row as $key => $value) {
    
    			// format any date values properly with WP date format
    			if ( strpos( $key, 'date' ) !== false || strpos( $key, 'modified' ) !== false ) {
    				$date_format = get_option( 'date_format' );
    				$value = mysql2date( $date_format, $value );
    			}
    			$row_vals[] = $value;
    		}
    		$rows[] = "<tr><td>" . join( '</td><td>', $row_vals ) . "</td></tr>";
    	}
    
    	// Put the table together and output
    	echo '<table class="wp-list-table widefat fixed posts">' . $header . '<tbody>' . join( $rows ) . '</tbody></table>';
    
    	return true;
    }
    
    /* Example usage with a menu page */
    function database_table_example_page() {
    
    	// example query: Posts published in last month
    	global $wpdb;
    	$posts_one_month = $wpdb->get_results("
    		SELECT `ID`, `post_title`, `post_modified`
    		FROM $wpdb->posts
    		WHERE $wpdb->posts.post_type = 'post'
    		AND $wpdb->posts.post_date > '" . date('Y-m-d H:i:s', strtotime('-1 month')) . "'
    		ORDER BY $wpdb->posts.post_date DESC
    	", ARRAY_A );
    
    	?>
    		<div class="wrap">
    			<h1>Last Month's Posts</h1>
    			<?php data_table( $posts_one_month ); ?>
    		</div>
    	<?php
    }
    
    /* Register menu page to use for example */
    function register_example_page() {
      add_menu_page( 'Database Table Example', 'DB Table (demo)', 'manage_options', 'example', 'database_table_example_page', 'dashicons-list-view', 90 );
    }
    add_action( 'admin_menu', 'register_example_page' );
    
    ?>
    
    

    public by simonwalker  156  0  4  0

    Magento 2 Canonical URLs Extension By FME

    Magento 2 Canonical URL extension helps you remove duplicate content issues from your eCommerce website with the addition of canonical Meta tags. You can add Magento canonical tags to products, categories, and CMS pages to define its relevancy with other pages. Magento canonical tags extension can configure the addition of canonical meta tags to a
    // Enter here the actual content of the snippet.						

    public by msdn  741  0  5  0

    HasMoreResultsInPage: Checks if the result segment has more results in the current page if pagination is used. If pagination is not used, it checks if a valid continuation is present.

    Checks if the result segment has more results in the current page if pagination is used. If pagination is not used, it checks if a valid continuation is present. The pagination. The continuation token. Returns true if there are more results in the page; otherwise, false.
    /// <summary>
    /// Checks if the result segment has more results in the current page if pagination is used.
    /// If pagination is not used, it checks if a valid continuation is present.
    /// </summary>
    /// <param name="pagination">The pagination.</param>
    /// <param name="continuationToken">The continuation token.</param>
    /// <returns>
    /// Returns <c>true</c> if there are more results in the page; otherwise, <c>false</c>.
    /// </returns>
    internal static bool HasMoreResultsInPage(ResultPagination pagination, ResultContinuation continuationToken)
    {
        bool hasContinuation = HasContinuation(continuationToken);
    
        if (pagination.IsPagingEnabled)
        {
            return !pagination.IsPageCompleted && hasContinuation;
        }
    
        return hasContinuation;
    }

    public by msdn  1191  0  6  0

    RewriteQueryForTakeCount: Rewrites the query for take count.

    Rewrites the query for take count. The local query. The pagination. The rewritten query.
    /// <summary>
    /// Stores the maximum results the table service can return.
    /// </summary>
    internal const int TableServiceMaxResults = 1000;
    
    /// <summary>
    /// Rewrites the query for take count.
    /// </summary>
    /// <param name="localQuery">The local query.</param>
    /// <param name="pagination">The pagination.</param>
    /// <returns>The rewritten query.</returns>
    private static DataServiceQuery<TElement> RewriteQueryForTakeCount(DataServiceQuery<TElement> localQuery, ResultPagination pagination)
    {
        int? nextRequestPageSize = pagination.GetNextRequestPageSize();
    
        if (pagination.IsPagingEnabled &&
            ((nextRequestPageSize != pagination.EffectivePageSize) ||
            pagination.EffectivePageSize > TableServiceMaxResults))
        {
            var expression = localQuery.Expression as MethodCallExpression;
            var adjustedTakeExpression = Expression.Call(
                expression.Object,
                expression.Method,
                expression.Arguments[0],
                Expression.Constant(Math.Min(nextRequestPageSize.Value, TableServiceMaxResults)));
    
            return localQuery.Provider.CreateQuery<TElement>(adjustedTakeExpression) as DataServiceQuery<TElement>;
        }
    
        return localQuery;
    }

    public by msdn  557  0  5  0

    CreateResultSegment: Create a result segment from the result result.

    Create a result segment from the result result. The type of the result. The set result. The result list. The continuation token. The pagination. The retry policy. The continuation function.
    /// <summary>
    /// Create a result segment from the result result.
    /// </summary>
    /// <typeparam name="T">The type of the result.</typeparam>
    /// <param name="setResult">The set result.</param>
    /// <param name="resultList">The result list.</param>
    /// <param name="continuationToken">The continuation token.</param>
    /// <param name="pagination">The pagination.</param>
    /// <param name="retryPolicy">The retry policy.</param>
    /// <param name="continuationFunction">The continuation function.</param>
    internal static void CreateResultSegment<T>(
        Action<ResultSegment<T>> setResult,
        IEnumerable<T> resultList,
        ResultContinuation continuationToken,
        ResultPagination pagination,
        RetryPolicy retryPolicy,
        Func<ResultPagination, ResultContinuation, Action<ResultSegment<T>>, TaskSequence> continuationFunction)
    {
        pagination.UpdatePaginationForResult(resultList.Count());
    
        setResult(new ResultSegment<T>(
            resultList,
            HasMoreResultsInPage(pagination, continuationToken),
            (setResultInner) => continuationFunction(pagination, continuationToken, setResultInner),
            retryPolicy)
            {
                ContinuationToken = continuationToken,
            });
    }

    external by allhailwesttexas  241375  9  4  1

    Flask/Jinja2 macro for rendering pagination in a template with Bootstrap components. Can center the component by wrapping in <nav class="text-center">.

    Flask/Jinja2 macro for rendering pagination in a template with Bootstrap components. Can center the component by wrapping in .: pagination_macros.html
    {% macro render_pagination(pagination, endpoint) %}
    
      <ul class="pagination">
    
        {% if pagination.has_prev %}
          <li>
            <a href="{{ url_for(endpoint, page=pagination.prev_num) }}" aria-label="Previous">
              <span aria-hidden="true">&laquo;</span>
            </a>
          </li>
        {% endif %}
    
        {% for p in pagination.iter_pages(left_edge=1, left_current=2, right_current=3, right_edge=1) %}
          {% if p %}
            {% if p != pagination.page %}
              <li>
                <a href="{{ url_for(endpoint, page=p) }}">{{ p }}</a>
              </li>
            {% else %}
              <li class="active">
                <a href="{{ url_for(endpoint, page=p) }}">{{ p }}</a>
              </li>
            {% endif %}
          {% else %}
            <li class="disabled">
              <span class="ellipsis">&hellip;</span>
            </li>
          {% endif %}
        {% endfor %}
    
        {% if pagination.has_next %}
          <li>
            <a href="{{ url_for(endpoint, page=pagination.next_num) }}" aria-label="Next">
              <span aria-hidden="true">&raquo;</span>
            </a>
          </li>
        {% endif %}
    
      </ul>
    
    {% endmacro %}
    
    
    

    external by stevesun21  57  0  1  0

    Pagination design in Domain Driven Design (https://medium.com/@stevesun21/pagination-in-domain-driven-design-c038c6858ac0)

    Pagination design in Domain Driven Design (https://medium.com/@stevesun21/pagination-in-domain-driven-design-c038c6858ac0): gistfile1.txt
    C
    /**
     * Copyright [2014] [SteveSun21]
     * 
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     * 
     *     http://www.apache.org/licenses/LICENSE-2.0
     * 
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
     
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.ParameterizedType;
    import java.lang.reflect.Type;
    import java.util.List;
     
    public abstract class PaginatedResult<T> {
    	
    	private Object delegate;
    	private String methodName;
    	private Object[] arguments;
    	private Method method;
    	
    	public PaginatedResult(Object delegate, String methodName, Object[] arguments) {
    		this.delegate = delegate;
    		this.methodName = methodName;
    		this.arguments = arguments;
    		loadMethod();
    	}
    	
    	private void loadMethod() {
    		try {
    			Class<?>[] parameterClasses = getParameterClasses();
    			method = delegate.getClass().getDeclaredMethod(methodName, parameterClasses);
    			method.setAccessible(true);
    		} catch (NoSuchMethodException | SecurityException e) {
    			e.printStackTrace();
    		}
    		checkForReturnType();
    	}
    	
    	private Class<?>[] getParameterClasses() {
    		Class<?>[] parameterClasses = new Class<?>[this.arguments.length + 1];
    		for (int i=0; i<this.arguments.length; i++) {
    			parameterClasses[i] = this.arguments[i].getClass();
    		}
    		parameterClasses[parameterClasses.length - 1] = Object.class;
    		return parameterClasses;
    	}
    	
    	private void checkForReturnType() {
    		Class<?> returnType = method.getReturnType();
    		Type returnElementType = this.method.getGenericReturnType();
    		Type returnItemType = ((ParameterizedType) returnElementType).getActualTypeArguments()[0];
    		if (!List.class.equals(returnType)
    				|| !getTypeArgument().equals(returnItemType)) {
    			throw new IllegalArgumentException("Need to return List<T>");
    		}
    	}
    	
    	private Type getTypeArgument() {
    		Type superClass = this.getClass().getGenericSuperclass();
    		Type type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
    		return type;
    	}
     
    	public List<T> getAllResults() {
    		return getResult(null);
    	}
    	
    	@SuppressWarnings("unchecked")
    	public List<T> getResult(Object pageCursor) {
    		List<T> result = null;
    		try {
    			result = (List<T>) method.invoke(delegate, addPageCursorToArguments(null));
    		} catch (IllegalAccessException | IllegalArgumentException
    				| InvocationTargetException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return result;
    	}
    	
    	private Object[] addPageCursorToArguments(Object pageCursor) {
    		Object[] clone = new Object[arguments.length + 1];
    		for (int i=0; i<arguments.length; i++) {
    			clone[i] = arguments[i];
    		}
    		clone[clone.length - 1] = pageCursor;
    		return clone;
    	}
    	
    }
    
    

    external by Jack Gregory  7962  161  4  0

    Change default WooCommerce pagination prev and next text

    Change default WooCommerce pagination prev and next text: gistfile1.txt
    add_filter( 'woocommerce_pagination_args' , 'custom_override_pagination_args' );
    
    function custom_override_pagination_args( $args ) {
    	$args['prev_text'] = __( '&laquo; Prev' );
    	$args['next_text'] = __( 'Next &raquo;' );
    	return $args;
    }
    
    
    • Public Snippets
    • Channels Snippets