Include parameters for a pagination system

I have a script that fetches data from my database and generates pagination. Everything is working fine, but now I want to include a conditional statement to differentiate the user level as New, Current, or Renewing client.

I've already set up some styles in my CSS using level_styles, so I can add a div style based on the user level. However, I'm not sure where and how to implement this conditional statement.

If anyone can provide assistance, it would be greatly appreciated. The plugin I used for pagination can be found here.

Thank you!

var columns = ["username", "user_id", "address", "state", "postal_code", "phone", "email"];
var level_classes = {
  "NEW": "new_client",
  "RENEWAL": "renewing_client",
  "CURRENT": "current_client"
};
$(document).ready(function() {
  var obj = '';
  $.getJSON("obtainUsers.php", function(data) {
    var num = 1;
    var json = JSON.stringify(data);
    obj = jQuery.parseJSON(json);
    var html = "";
    var tot_obj = obj.length;
    var highest = (num * 8) - 1;
    var lowest = (num * 8) - 8;
    var maximum = (highest < total_users) ? highest : total_users;
    for (var i = lowest; i <= maximum; i++) {
      var toggle = i % 2;
      var textTab = " ";
      for (var x = 0; x < columns.length; x++) {
        if (typeof obj[i][columns[x]] === 'undefined' || obj[i][columns[x]] === "") {
          continue;
        }
        var tmp = "";
        if (obj[i][columns[x]] instanceof Object) {
          tmp += obj[i][columns[x]];
        }
        if (tmp && tmp !== ' ') {
          textTab += tmp;
        }
        textTab += "<br />";
      }
      if (toggle == 0) {
        html += "<div style='text-align: center;'>";
        html += textTab;
        html += "</div>";
      } else {
        html += "<div style='text-align: center;'>";
        html += textTab;
        html += "</div>";
      }
    }
    $('.testid').html(html);
  });
  $('.pagination, .pagination_bottom').bootpag({
    total: 20,
    page: 1,
    leaps: false,
    next: 'next',
    prev: 'prev',
    maximumVisible: 3
  }).on('page', function(event, num) {
    var html = "";
    var total_users = obj.length;
    var highest = (num * 9) - 1;
    var lowest = (num * 9) - 9;
    var maximum = (highest < total_users) ? highest : total_users;
    for (var i = lowest; i < maximum; i++) {
      var toggle = i % 2;
      var textTab = " ";
      for (var x = 0; x < columns.length; x++) {
        
        if (typeof obj[i][columns[x]] === 'undefined' || obj[i][columns[x]] === "") {
          continue;
        }
        var tmp = "";
        if (obj[i][columns[x]] instanceof Object) {
          tmp += obj[i][columns[x]];
        }
        if (tmp && tmp !== ' ') {
          textTab += tmp;
        }
        textTab += "<br />";
      }
      if (toggle == 0) {
        html += "<div style='text-align: center;'>";
       
        html += textTab;
        html += "</div>";
      } else {
        html += "<div style='text-align: center;'>";
        html += textTab;
        html += "</div>";
      }
    }
    $('.runningList').html(html);
    var total_pages = Math.ceil(obj.length / 10);
    $('.pagination_bottom').bootpag({
      page: num,
      total: total_pages
    });
  });
});

Answer №1

Here is the solution I came up with

if( columns[x] == "user_level" && obj[i][columns[x]] == new_user )
{
    textTab += "<span class='new_user'>";
}                                
else if ( columns[x] == "user_level" && obj[i][columns[x]] == current_user )
{
    textTab += "<span class='current_user'>";
}
else if ( columns[x] == "user_level" && obj[i][columns[x]] == renew_user )
{
    textTab += "<span class='renewing_user'>";
}

I defined the variables new_user, current_user and renew_user for these conditions

if (typeof obj[i][columns[x]] === 'undefined' || obj[i][columns[x]] === "") {
      continue;
    }
//Added the conditions here
var tmp = "";

I want to express my gratitude to @humble.rumble.6x3

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Make sure the text fits perfectly without any extra spaces

When working with CSS/HTML, I noticed that using a simple text within a div without any margin or padding, and specifying a font-size of 36px with a line-height also set to 36px doesn't fit perfectly - there is always some spacing at the top of the li ...

My Express server is having trouble loading the Static JS

I'm feeling frustrated about this particular issue. The problem seems to be well-solved, and my code looks fine, but I can't figure out what's wrong . . . I have a JavaScript file connecting to my survey page, which I've added at the b ...

How can PHP be utilized to dynamically add classes to <li> elements and alternate them after every third item

I'm trying to find a way to add a class to an unordered list and alternate that class after every third item. Here's the code I have so far: <?php $i=1; foreach($this->items as $item) : ?> <li class="<?php if ($i % 3 == 0) : ...

What is the best way to target all elements sharing a common class?

Currently, I have a Boolean variable stored in a hidden input field. When the user is signed in, it's set to false; otherwise, it's set to true. I have download buttons that should link to a file for download. My goal is to hide these buttons an ...

Length of borders at the bottom of `td` elements in tables

I have been searching everywhere for a solution and just can't seem to figure it out. I am trying to adjust the length of the bottom border for td elements within a table. I have attached two screenshots for reference. Any assistance would be greatly ...

Mysterious attributes - utilizing react and material-ui

In my current project, I am using react and material-ui. This is the code snippet from one of my components: <Dialog title="Dialog With Actions" actions={actions} modal={false} open={this.state.open} onRequestClose={this.handleClose ...

What is the best way to design a timetable schema in MongoDB specifically for a Teacher Schema?

Greetings to all in the StackOverflow community! I am here seeking some innovative ideas for a project I am currently working on. One of the challenges I'm facing involves storing available days within a Teacher Schema. In this application, a Teacher ...

What is the reason behind this Uncaught TypeError that is happening?

After converting my questionnaire to a PHP file and adding a validation script, I encountered an error: Uncaught TypeError: Cannot set property 'onClick' of null The error is pointing me to line 163 in my JavaScript file, where the function f ...

When launching JQuery UI Tabs in a new browser tab using ajax, the HTML from the ajax response will be immediately shown

I am currently in the process of upgrading from JQuery UI 1.8.14 to JQuery UI 1.10. Previously, when using v1.8.14 code, opening a tab in a new browser tab would cause the entire page to reload, activating the default tab (tabIndex=0). However, I am faci ...

What is the best way to set up the upcoming AJAX call?

When I hit the start button, it seems to be sending the request multiple times. How can I resolve this issue? Check out this GIF The request should only be sent once. Here is a jsfiddle link for reference $(document).ready(function () { $("#json ...

Reposition icons accordingly while incorporating a new set of icons

After creating a new icon set font, I noticed that the icons are not positioning correctly and appear smaller than expected when loaded: https://i.stack.imgur.com/1OsAL.png https://i.stack.imgur.com/zmLQq.png I attempted to adjust the .icon class by add ...

Utilize CSS to style active buttons with JavaScript

In an HTML document, the dynamic generation of divs and buttons using JavaScript can be seen in the code snippet below. <div style="background: rgb(247, 247, 247);"> <button class ="xyz" disabled="disabled">Button1</button> </div> ...

Switch off any other currently open divs

I'm currently exploring a way to automatically close other div's when I expand one. Check out my code snippet below: $( document ).ready(function() { $( ".faq-question" ).click(function() { $(this).toggleClass('open'); $(this ...

What is the best way to integrate a CSS designed flag in my website's top navigation bar?

My goal is to make my website multilingual, allowing users to switch between languages using flags in a dropdown menu. Initially, I tried creating the flag images solely with CSS for better resizing ability but faced difficulties. So, I resorted to using s ...

Error: The PDFJS variable is not recognized when trying to load a PDF file

I've been experimenting with pdf.js to load PDFs into a web application in order to extract information in real-time. However, I keep encountering an error even with a simple example. I've attempted enclosing the code in $(document).ready() as a ...

The value returned when using $.css('transform') is incorrect and displays as "rotate"

Possible Duplicate: Retrieve -moz-transform:rotate value using jQuery Firefox 15 - Chrome: $('#img2').css('transform'); return => "rotate(90deg)" Firefox 16 $('#img2').css('transform'); return => mat ...

What are the best methods for concealing a ng-repeat element with AngularJS?

.controller('CouponsCtrl', ['$scope', '$http', '$window', '$location', '$ionicPopup','$ionicLoading', function($scope, $http, $window, $location, $ionicPopup,$ionicLoading) { ...

Is incorporating re-routing into an action a beneficial approach?

My main concern involves action design strategies: determining the best timing and method for invoking actions. In my project using Mantra (utilizing React for the front-end and Meteor's FlowRouter for routing), there is a UI component that includes ...

Move the cursor within the text area upon clicking the button

When the "+header" button is clicked, I am looking to automatically position the insertion point inside the text area. Currently, after pressing the button, the text box displays information like address, date, time etc. but the cursor does not start insid ...

Delete an item from an array when a dropdown selection is made

When dealing with Angular 8, I encountered a logic issue. There are two drop-down menus: First Drop-down The options in the first menu are populated from an array of objects Example Code, ts: {rs_id: "a5f100d5-bc88-4456-b507-1161575f8819", ...