{"id":16318323,"url":"https://github.com/romansoloweow/pagination","last_synced_at":"2025-05-13T17:40:00.637Z","repository":{"id":116593374,"uuid":"331979944","full_name":"RomanSoloweow/Pagination","owner":"RomanSoloweow","description":"Paginator display algorithm","archived":false,"fork":false,"pushed_at":"2021-01-22T15:18:47.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-16T08:28:04.919Z","etag":null,"topics":["csharp","pagination","paginator"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RomanSoloweow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-01-22T15:06:54.000Z","updated_at":"2021-02-26T01:48:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"f88b63d4-5fe6-4aa3-9a83-fffc94ee6cf1","html_url":"https://github.com/RomanSoloweow/Pagination","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"85cc32fe05b386be6183ce57d1937db6951602c2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RomanSoloweow%2FPagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RomanSoloweow%2FPagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RomanSoloweow%2FPagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RomanSoloweow%2FPagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RomanSoloweow","download_url":"https://codeload.github.com/RomanSoloweow/Pagination/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239195277,"owners_count":19598035,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","pagination","paginator"],"created_at":"2024-10-10T22:23:09.162Z","updated_at":"2025-02-16T20:36:15.156Z","avatar_url":"https://github.com/RomanSoloweow.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pagination\n\n![paginator](https://user-images.githubusercontent.com/29205560/105506959-ae7db800-5cdb-11eb-98c2-26469566dc1e.png)\n\n## Algorithm code\n``` c#\nint countRecords = ...;\nint countOnPage = ...;\nint currentPage = ...;\n    \nif (countRecords \u003e 0 \u0026\u0026 countOnPage \u003e 0)\n{\n    int pageSkip = currentPage-1;//how many pages are skipped\n    int countPages = (int)Math.Ceiling((countRecords / 1.0) / countOnPage); //how many pages\n    int countOtherPage = countPages - currentPage;//how many pages are ahead\n\n    int step = 2;//Indent to the left and right of the current page in the center block\n    int stepLeft = 2;//size of left part\n    int stepRight = 2;//size of right part\n\n    //Left and right values calculation\n    int left = (pageSkip \u003e= step) ? step : pageSkip % (step);\n    int right = (countOtherPage \u003e= step) ? step : countOtherPage % (step);\n\n \n    if (left + right \u003c countPages - 1)\n    {\n        // if not enough on the left - add on the right (so that there are always 2 * step + 1 pages)\n        if (left \u003c step)\n        {\n            int diff = step - left;\n            diff = ((countOtherPage \u003e= (right + diff)) ? diff : countOtherPage - diff);\n            right += diff \u003e 0 ? diff : 0;\n        }\n\n       // if not enough on the right - add on the left (so that there are always 2 * step + 1 pages)\n        if (right \u003c step)\n        {\n            int diff = step - right;\n            diff = (pageSkip \u003e= (left + diff)) ? diff : pageSkip - diff;\n            left += diff \u003e 0 ? diff : 0;\n        }\n    }\n\n    //Go to page button\n    if (countPages \u003e (2 * step + 1))//if not all pages fit into the central panel\n    {\n        //Here you create go to page button with input\n    }\n\n    //Left part\n    if (pageSkip \u003e left)\n    {\n        int diff = (pageSkip \u003e= (step + stepLeft)) ? stepLeft : (pageSkip - step);\n\n        for (int i = 1; i \u003c 1 + diff; i++)\n        {\n          //Here you create buttons with a redirect to the i-th page\n        }\n\n       //here \u003ca\u003e...\u003c/a\u003e\n    }\n\n    //Middle part\n    if (countPages \u003e 1)\n    {\n        for (int i = currentPage - left; i \u003c= currentPage + right; i++)\n        {\n            //Here you create buttons with a redirect to the i-th page\n        }\n    }\n\n    //Right part\n    if(countOtherPage\u003e right)\n    {\n        //here \u003ca\u003e...\u003c/a\u003e\n        int diff = (countOtherPage \u003e= (step + stepRight)) ? stepRight : (countOtherPage - step);\n        for (int i = countPages - diff + 1; i \u003c= countPages; i++)\n        {\n            //Here you create buttons with a redirect to the i-th page\n        }\n    }\n}\n``` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromansoloweow%2Fpagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromansoloweow%2Fpagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromansoloweow%2Fpagination/lists"}