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="assets/libs/list.js/list.min.js"></script>
<!-- Pagination js -->
<script src="assets/libs/list.pagination.js/list.pagination.min.js"></script>
Initjs (Custom js)
<!-- listjs init -->
<script src="assets/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 table-customer-list.json file and add new field to json
example=>"customer_name": "Mary Cousar"
-
Go to listjs.init.js file and load that json file and add field in xhttp.onload function at line number 88 or below
example =>customer_name: raw.customer_name
-
Goto tables-listjs.html and set atrribute data-sort to attribute to th.
example=>data-sort="customer_name"
-
Goto listjs.init.js & at line number 110 ,Get the queryselector of required field.
example=>customerNameField = document.getElementById("customername-field")
-
listjs.init.js =>goto line number 192 of addbtn functionality
add required field details in if & else condition
example =>in if condition line number 195
customerNameField.value !== ""
=>in else condition
customer_name: customerNameField.value
-
listjs.init.js => at line number 224 of edit button functionality
follow the same procedure of add button
-
listjs.init.js => at line number 346 of clearFileds function & add field ad below
customerNameField.value = "";
To delete field from table
-
To Delete a single record
listjs.init.js =>At line number 287 of refreshCallbacks() function
And use removeBtns functionality to delete single record
-
To Delete Multiple records
listjs.init.js => At Line number 353 of deleteMultiple() function
and use deleteMultiple() functionality to remove all records
Tab content wise data filter
-
Goto apps-ecommerce-orders.html & add following code available at line number 102 to 128
<ul class="nav nav-tabs nav-tabs-custom nav-success mb-3" role="tablist"> <li class="nav-item"> <a class="nav-link active All py-3" data-bs-toggle="tab" id="All" href="#home1" role="tab" aria-selected="true"> <i class="ri-store-2-fill me-1 align-bottom"></i> All Orders </a> </li> <li class="nav-item"> <a class="nav-link py-3 Delivered" data-bs-toggle="tab" id="Delivered" href="#delivered" role="tab" aria-selected="false"> <i class="ri-checkbox-circle-line me-1 align-bottom"></i> Delivered </a> </li> <li class="nav-item"> <a class="nav-link py-3 Pickups" data-bs-toggle="tab" id="Pickups" href="#pickups" role="tab" aria-selected="false"> <i class="ri-truck-line me-1 align-bottom"></i> Pickups <span class="badge bg-danger align-middle ms-1">2</span> </a> </li> <li class="nav-item"> <a class="nav-link py-3 Returns" data-bs-toggle="tab" id="Returns" href="#returns" role="tab" aria-selected="false"> <i class="ri-arrow-left-right-fill me-1 align-bottom"></i> Returns </a> </li> <li class="nav-item"> <a class="nav-link py-3 Cancelled" data-bs-toggle="tab" id="Cancelled" href="#cancelled" role="tab" aria-selected="false"> <i class="ri-close-circle-line me-1 align-bottom"></i> Cancelled </a> </li> </ul>
-
Go to ecommerce-order.init.js & add following code available at line number 153 to 178
var tabEl = document.querySelectorAll('a[data-bs-toggle="tab"]'); Array.from(tabEl).forEach(function (item) { item.addEventListener("shown.bs.tab", function (event) { filterOrder(event.target.id); }); }); function filterOrder(isValue) { var values_status = isValue; orderList.filter(function (data) { var statusFilter = false; matchData = new DOMParser().parseFromString( data.values().status, "text/html" ); var status = matchData.body.firstElementChild.innerHTML; if (status == "All" || values_status == "All") { statusFilter = true; } else { statusFilter = status == values_status; } return statusFilter; }); orderList.update(); }
To search record
-
Goto ecommerce-order.init.js & add following code available at line number 229 to 277
function SearchData() { var isstatus = document.getElementById("idStatus").value; var payment = document.getElementById("idPayment").value; var pickerVal = document.getElementById("demo-datepicker").value; var date1 = pickerVal.split(" to ")[0]; var date2 = pickerVal.split(" to ")[1]; orderList.filter(function (data) { matchData = new DOMParser().parseFromString( data.values().status, "text/html" ); var status = matchData.body.firstElementChild.innerHTML; var statusFilter = false; var paymentFilter = false; var dateFilter = false; if (status == "all" || isstatus == "all") { statusFilter = true; } else { statusFilter = status == isstatus; } if (data.values().payment == "all" || payment == "all") { paymentFilter = true; } else { paymentFilter = data.values().payment == payment; } if ( new Date(data.values().date.slice(0, 12)) >= new Date(date1) && new Date(data.values().date.slice(0, 12)) <= new Date(date2) ) { dateFilter = true; } else { dateFilter = false; } if (statusFilter && paymentFilter && dateFilter) { return statusFilter && paymentFilter && dateFilter; } else if (statusFilter && paymentFilter && pickerVal == "") { return statusFilter && paymentFilter; } else if (paymentFilter && dateFilter && pickerVal == "") { return paymentFilter && dateFilter; } }); orderList.update(); }