List Js
OverviewOfficial Website
List js is a library for adding search, sort, filters and flexibility to tables, lists and various HTML elements.
Javascript
<!-- List js -->
<script src="/static/libs/list.js/list.min.js"></script>
<!-- Pagination js -->
<script src="/static/libs/list.pagination.js/list.pagination.min.js"></script>
Initjs (Custom js)
<!-- listjs init -->
<script src="/static/js/pages/listjs.init.js"></script
Add Package
yarn add list.js --save
Remove Package
yarn remove list.js or you can remove package by removing specific package from package.json
Examples
Title | Javascript |
---|---|
Data Attributes + Custom |
|
Existing List |
|
Fuzzy Search |
|
Pagination |
|
To add new field to table
-
Goto sellers-list.json file and add new field to json
example=>"sellerName": "Alfred Hurst"
-
Go to sellers-list.init.js file and load that json file and add field in xhttp.onload function at line number 75 or below
example =>sellerName: element.sellerName
-
Goto sellers-list.init.js.html and set atrribute data-sort to attribute to th.
example=>data-sort="sellerName"
-
Goto sellers-list.init.js & at line number 118 ,Get the queryselector of required field.
example=>sellerNameField = document.getElementById("seller-name-field")
-
sellers-list.init.js =>goto line number 235 of addbtn functionality
add required field details in if & else condition
example =>in if condition line number 249
sellerNameField.value !== ""
=>in else condition
sellerName: sellerNameField.value
-
sellers-list.init.js => at line number 307 of edit button functionality
follow the same procedure of add button
-
sellers-list.init.js => at line number 356 of clearFileds function & add field ad below
sellerNameField.value = "";
To delete field from table
-
To Delete a single record
sellers-list.init.js =>At line number 175 of refreshCallbacks() function
And use removeBtns functionality to delete single record
-
To Delete Multiple records
sellers-list.init.js => At Line number 399 of deleteMultiple() function
and use deleteMultiple() functionality to remove all records
Tab content wise data filter
-
Go to sellers-list.init.js & add following code available at line number 359 to 385
var statusInput = new Choices(document.getElementById('idStatus'), { searchEnabled: false, }); statusInput.passedElement.element.addEventListener('change', function (event) { var statusInputValue = event.detail.value; sellersList.filter(function (data) { matchData = new DOMParser().parseFromString( data.values().accountStatus, "text/html" ); var status = matchData.body.firstElementChild.innerHTML; var statusFilter = false; if (status == "All" || statusInputValue == "All") { statusFilter = true; } else { statusFilter = status == statusInputValue; } if (statusFilter) { return statusFilter; } }); sellersList.update(); }, false);
To search record
-
Get enable to just search functionality in seller-list-view.html