/    Sign up×
Community /Pin to ProfileBookmark

JavaScript pagination dynamical

Hi

I’m trying to dynamic pagination in JavaScript ,i attached file Zip file
Please i Need help from any one ,i’m New to JavaScript

Thank you and Appreciate your help

My Repository files are available JavaScript pagination
https://github.com/332865245/MyRepository

to post a comment

17 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJul 15.2019 — Please describe your issue: What do you expect the code to do? What happens instead? Did you code that pager yourself or is it some third party script?
Copy linkTweet thisAlerts:
@Deepu15authorJul 16.2019 — @Sempervivum#1606313

i'm try to do dynamical pagination and HTML <P> tag it has to generated dynamically from this function "readValue()"

dynamically <p> tag generates and displaying in div tag and <div id='listTable'> </div> and it not working the pagination

ele.innerHTML += '<p><a href="javascript:editParameters(' '+key+'');">'+value+'</a></p>';



if i do hard code <p> tag generates and displaying in div tag and pagination is working fine

<div id='listTable'>

<p><a href="javascript:editParameters(' test_31');">Display values-31</a></p>

<p><a href="javascript:editParameters(' test_051');">Display values-051</a></p>

<p><a href="javascript:editParameters(' test_01');">Display values-01</a></p>

<p><a href="javascript:editParameters(' test_25');">Display values-25</a></p>

<p><a href="javascript:editParameters(' test_21');">Display values-21</a></p>

<p><a href="javascript:editParameters(' test_15');">Display values-2423</a></p>

<p><a href="javascript:editParameters(' test_14');">Display values-253</a></p>

<p><a href="javascript:editParameters(' test_16');">Display values-24</a></p>

<p><a href="javascript:editParameters(' test_12');">Display values-22</a></p>

<p><a href="javascript:editParameters(' test_11');">Display values-21</a></p>

</div>


i want to do dynamically

[upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-07-16/1563259552-563155-pagination.png]

Thank you and Appreciate your help
Copy linkTweet thisAlerts:
@SempervivumJul 16.2019 — Unfortunately I still don't understand :-(
Copy linkTweet thisAlerts:
@SempervivumJul 16.2019 — Now I understand, the image is helpful. The reason why it doesn't work is: You call readValue which creates the list of p tags on load. However you create the pager on document-ready. document-ready fires [b]before[/b] onload; at this time the list of p elements is not yet created.

Remove readValue from the onload for body and call it before creating the pager:
&lt;body&gt;
&lt;!-- stuff (HTML and JS) as previously --&gt;
&lt;script type="text/javascript"&gt;
readValue();
var pager = new Imtech.Pager();
//$(document).ready(function () {
pager.paragraphsPerPage = 5; // set amount elements per page
pager.pagingContainer = $('#listTable'); // set of main container
pager.paragraphs = $('p', pager.pagingContainer); // set of required containers
pager.showPage(1);
//});
&lt;/script&gt;
&lt;/body&gt;
Copy linkTweet thisAlerts:
@Deepu15authorJul 16.2019 — @Sempervivum#1606339

Excellent and Appreciate your help

learning new things

in CSS

i try to display the background color when mouse click on pagination number active the background color and to shoud not change the background color until next page click

#listTable p{

text-indent:2px;

text-align:justify;

}

#pagingControls ul{

display:inline;

padding-left:0.5em

}

#pagingControls li{

display:inline;

padding:0 0.2em;

}

#pagingControls li a:hover {

background: #00bce1;

color: #fff !important;

border: 1px solid #00bce1;

}

#pagingControls li a.active {

outline: none;

background-color: #00bce1;

color: #fff !important;

border: 1px solid #00bce1;

}


[upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-07-16/1563284586-122435-pagination-background-color.png]
Copy linkTweet thisAlerts:
@Deepu15authorJul 16.2019 — @Deepu15#1606345

i got it, Sorry for trouble
Copy linkTweet thisAlerts:
@SempervivumJul 16.2019 — Not shure if I understand this completely: Currently the background color is turquoise on hover. You wish that the bg of the number is colorised permanently after click. Do you wish to keep the colorising on hover additionally?
Copy linkTweet thisAlerts:
@SempervivumJul 16.2019 — I see, that's fine. Our posting crossed.
Copy linkTweet thisAlerts:
@Deepu15authorJul 16.2019 — @Sempervivum#1606347

Thank you for help ,i got the solution
Copy linkTweet thisAlerts:
@Deepu15authorJul 18.2019 — @Sempervivum#1606339

Thank you and Appreciate your help

how to refresh the Div tag , when we set the data first time the pagination in not displaying , when we refresh the page the it is displaying and even when i delete the particular record it as to refresh the div tag

Could you Please have any idea

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h4&gt;The set the local Storage&lt;/h4&gt;
&lt;button onclick="createItem()"&gt;Set local storage item&lt;/button&gt;
&lt;h4&gt;Get the value&lt;/h4&gt;

&lt;br/&gt;
&lt;p&gt;paging Controls&lt;/p&gt;
&lt;div id="pagingControls"&gt;&lt;/div&gt;
&lt;div id='listTable'&gt; &lt;/div&gt;

&lt;script&gt;
/******this is for testing****/
/***remove this to persist data***/

function createItem() {

var myStorage={
Items : [],
setItem : function(key,value){
var obj = {}; obj [key] = value;
this.Items.push(obj);
localStorage.setItem('myStorage',JSON.stringify(this))
}
}
myStorage.setItem("test_11", "Display values-21");
myStorage.setItem("test_12", "Display values-22"); <br/>
myStorage.setItem("test_16", "Display values-24");
myStorage.setItem("test_14", "Display values-253");
myStorage.setItem("test_15", "Display values-2423");
myStorage.setItem("test_21", "Display values-21");
myStorage.setItem("test_25", "Display values-25");
myStorage.setItem("test_01", "Display values-01");
myStorage.setItem("test_051", "Display values-051");
myStorage.setItem("test_31", "Display values-31");
readValue();
}
function readValue() {
var ele = document.getElementById("listTable");
var stored = JSON.parse(localStorage.getItem('myStorage'),true).Items;
for (var i = stored.length; i ; i--) {
var obj = stored[i-1];
var key = Object.keys(obj)[0];
var value = (obj)[key]; <br/>
ele.innerHTML += '&lt;p&gt;&lt;a href="javascript:editParameters(' '+key+'');"&gt;'+value+'&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:deleteParameters(''+key+'');"&gt;Delete&lt;/a&gt;&lt;/p&gt;';

}
}

function deleteParameters(key){
alert(key);
localStorage.removeItem(key);
}
&lt;/script&gt;
&lt;link rel="stylesheet" href="pagination.css" type="text/css" /&gt;
&lt;script src="jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="imtech_pager.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var pager = new Imtech.Pager();
readValue()
$(document).ready(function() {
pager.paragraphsPerPage = 3; // set amount elements per page
pager.pagingContainer = $('#listTable'); // set of main container
pager.paragraphs = $('p', pager.pagingContainer); // set of required containers
pager.showPage(1);
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;


https://github.com/332865245/MyRepository

Edited by site staff: Corrected code tags
Copy linkTweet thisAlerts:
@SempervivumJul 18.2019 — You need to initialise the pager after having created the items:
function readValue() {
var ele = document.getElementById("listTable");
var stored = JSON.parse(localStorage.getItem('myStorage'), true).Items;
for (var i = stored.length; i; i--) {
var obj = stored[i - 1];
var key = Object.keys(obj)[0];
var value = (obj)[key];

<i> </i> ele.innerHTML += '&lt;p&gt;&lt;a href="javascript:editParameters(' ' + key + '');"&gt;' + value + '&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:deleteParameters('' + key + '');"&gt;Delete&lt;/a&gt;&lt;/p&gt;';

<i> </i> }
<i> </i> pager.paragraphsPerPage = 3; // set amount elements per page
<i> </i> pager.pagingContainer = $('#listTable'); // set of main container
<i> </i> pager.paragraphs = $('p', pager.pagingContainer); // set of required containers
<i> </i> pager.showPage(1);
<i> </i> }
Copy linkTweet thisAlerts:
@Deepu15authorJul 18.2019 — @Sempervivum#1606444

Hi

i already check this way and it is not working and also when we delete the particular key then the pagination as to reset the pages . i have no idea how to rest the pages when particular key is deleted

Thank you and Appreciate your help
Copy linkTweet thisAlerts:
@SempervivumJul 18.2019 — You didn't delete the item properly.
  • 1. Read items from local storage

  • 2. Find item to be deleted

  • 3. Delete that item

  • 4. Write back to local storage

  • 5. Read back from local storage by calling readValue

    (Reading back from local storage at 5. is obsolete, however I kept it in order to reuse the function readValue)

    This works for me:
    &lt;!DOCTYPE html&gt;
    &lt;html&gt;

    &lt;body&gt;
    &lt;h4&gt;The set the local Storage&lt;/h4&gt;
    &lt;button onclick="createItem()"&gt;Set local storage item&lt;/button&gt;
    &lt;h4&gt;Get the value&lt;/h4&gt;

    <i> </i>&lt;br /&gt;
    <i> </i>&lt;p&gt;paging Controls&lt;/p&gt;
    <i> </i>&lt;div id="pagingControls"&gt;&lt;/div&gt;
    <i> </i>&lt;div id="listTable"&gt; &lt;/div&gt;

    <i> </i>&lt;script&gt;
    <i> </i> /******this is for testing****/
    <i> </i> /***remove this to persist data***/

    <i> </i> function createItem() {

    <i> </i> var myStorage = {
    <i> </i> items: [],
    <i> </i> setItem: function (key, value) {
    <i> </i> var obj = {}; obj[key] = value;
    <i> </i> this.items.push(obj);
    <i> </i> localStorage.setItem('myStorage', JSON.stringify(this.items))
    <i> </i> }
    <i> </i> }

    <i> </i> myStorage.setItem("test_11", "Display values-21");
    <i> </i> myStorage.setItem("test_12", "Display values-22");

    <i> </i> myStorage.setItem("test_16", "Display values-24");
    <i> </i> myStorage.setItem("test_14", "Display values-253");
    <i> </i> myStorage.setItem("test_15", "Display values-2423");
    <i> </i> myStorage.setItem("test_21", "Display values-21");
    <i> </i> myStorage.setItem("test_25", "Display values-25");
    <i> </i> myStorage.setItem("test_01", "Display values-01");
    <i> </i> myStorage.setItem("test_051", "Display values-051");
    <i> </i> myStorage.setItem("test_31", "Display values-31");
    <i> </i> readValue();

    <i> </i> }
    <i> </i> function readValue() {
    <i> </i> var ele = document.getElementById("listTable");
    <i> </i> var stored = JSON.parse(localStorage.getItem('myStorage'), true);
    <i> </i> for (var i = stored.length; i; i--) {
    <i> </i> var obj = stored[i - 1];
    <i> </i> var key = Object.keys(obj)[0];
    <i> </i> var value = (obj)[key];

    <i> </i> ele.innerHTML += '&lt;p&gt;&lt;a href="javascript:editParameters(' ' + key + '');"&gt;' + value + '&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:deleteParameters('' + key + '');"&gt;Delete&lt;/a&gt;&lt;/p&gt;';

    <i> </i> }
    <i> </i> pager.paragraphsPerPage = 3; // set amount elements per page
    <i> </i> pager.pagingContainer = $('#listTable'); // set of main container
    <i> </i> pager.paragraphs = $('p', pager.pagingContainer); // set of required containers
    <i> </i> pager.showPage(1);
    <i> </i> }

    <i> </i> function deleteParameters(key) {
    <i> </i> console.log(key);
    <i> </i> var items = JSON.parse(localStorage.getItem('myStorage'));
    <i> </i> console.log(items);
    <i> </i> var index = -1;
    <i> </i> items.forEach(function (item, idx) {
    <i> </i> if (item[key]) index = idx;
    <i> </i> });
    <i> </i> items.splice(index, 1);

    <i> </i> localStorage.setItem('myStorage', JSON.stringify(items));
    <i> </i> readValue();
    <i> </i> }
    <i> </i>&lt;/script&gt;
    <i> </i>&lt;link rel="stylesheet" href="pagination.css" type="text/css" /&gt;
    <i> </i>&lt;script src="jquery.min.js"&gt;&lt;/script&gt;
    <i> </i>&lt;script src="imtech_pager.js"&gt;&lt;/script&gt;
    <i> </i>&lt;script type="text/javascript"&gt;
    <i> </i> var pager = new Imtech.Pager();
    <i> </i> // readValue();
    <i> </i>&lt;/script&gt;
    &lt;/body&gt;

    &lt;/html&gt;
  • Copy linkTweet thisAlerts:
    @Deepu15authorJul 18.2019 — @Sempervivum#1606448


    Thank you and Appreciate your help

    if you delete from 4th page , then it has to reset to 3 pages only right ,

    [upl-image-preview url=https://www.webdeveloper.com/assets/files/2019-07-18/1563463648-392969-pagination-del.png]
    Copy linkTweet thisAlerts:
    @SempervivumJul 18.2019 — Yes, it should. Doesn't it?
    Copy linkTweet thisAlerts:
    @zafirkalvinJul 18.2019 — What happens [url=https://onlinesbi.tips/][color=#000000]Onlinesbi[/color][/url] [url=https://thegadgetwire.com/tutuapp/][color=#000000]TutuApp[/color][/url] [url=https://aadharcard.vip/][color=#000000] aadhar card [/color][/url] instead? Did you code that pager yourself or is it some third party script?
    Copy linkTweet thisAlerts:
    @daveyerwinJul 18.2019 — ``<i>
    </i>&lt;!DOCTYPE html&gt;
    &lt;html&gt;
    &lt;link rel="stylesheet" href="pagination.css" type="text/css" /&gt;
    &lt;body&gt;
    &lt;h4&gt;The set the local Storage&lt;/h4&gt;
    &lt;button onclick="createItem()"&gt;Set local storage items&lt;/button&gt;
    &lt;button onclick="clearMyStorage()"&gt; Clear myStorage &lt;/button&gt;
    &lt;button onclick='listItems()'&gt; list all Items &lt;/button&gt;
    &lt;button onclick='listItems(0,3)'&gt; list first three Items &lt;/button&gt;
    &lt;button onclick="listItems(3,3)"&gt; list Items four five and six&lt;/button&gt;
    &lt;ul id=list&gt;&lt;/list&gt;
    &lt;script&gt;
    'use strict';
    function createItem() {
    clearMyStorage();
    myStorage.setItem("test_11", "Display values-21y");
    myStorage.setItem("test_12", "Display values-22");
    myStorage.setItem("test_16", "Display values-24");
    myStorage.setItem("test_14", "Display values-253");
    myStorage.setItem("test_15", "Display values-2423");
    myStorage.setItem("test_21", "Display values-21");
    myStorage.setItem("test_25", "Display values-25");
    myStorage.setItem("test_01", "Display values-01");
    myStorage.setItem("test_051","Display values-051");
    myStorage.setItem("test_31", "Display values-31");
    }
    function listItems(start,end){
    while (list.hasChildNodes())
    list.removeChild(list.lastChild);
    var i=0,item,keys=myStorage.getKeys();
    if(arguments.length == 0){
    while(item = myStorage.getItem(keys[i++])){
    fn();
    }
    } else {
    i = start;
    while(item = myStorage.getItem(keys[i++])){
    if(i&gt;end+start)return;
    fn();
    }
    }
    function fn(){
    var li = list.appendChild(document.createElement("li"));
    li.appendChild(document.createTextNode(item));
    ul = li.appendChild(document.createElement('ul'));
    ulli = ul.appendChild(document.createElement("li"));
    ulli.appendChild(document.createTextNode("DELETE"));
    ulli.onclick=(function(e){
    var a = keys[i-1], b = li;
    return function(){
    b.parentNode.removeChild(b);
    myStorage.deleteItem(a);
    }
    }()) }
    }
    function clearMyStorage(){
    myStorage.clear();
    while (list.hasChildNodes())
    list.removeChild(list.lastChild);
    }
    var myStorage = (function () {
    var stored = JSON.parse(localStorage.getItem('myStorage'),true),
    Items = stored ? stored:{},
    current = 0;
    function set(){localStorage.setItem('myStorage',JSON.stringify(Items))};
    return {
    setItem : function(key,value){
    if(!value)return;
    Items [key] = value ;
    set();
    },
    getItem : function(key) {
    return Items [key];
    },
    getKeys : function() {
    return Object.keys(Items);
    },
    deleteItem : function(key){
    delete Items [key];
    set();
    },
    clear: function() {
    Items = {};
    set();
    },
    }
    }());
    &lt;/script&gt;
    &lt;/body&gt;
    &lt;/html&gt;<i>
    </i>
    ``
    ×

    Success!

    Help @Deepu15 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.26,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...