tedirghazali / alga-js

Alga.js is javascript helper for helping build a component of any front-end web frameworks
https://algajs.tedir.dev
Other
18 stars 41 forks source link

app.js:26405 Uncaught TypeError: (0 , alga_js_array__WEBPACK_IMPORTED_MODULE_1__.paginate)(...) is not a function am getting this error #8

Open CodeNinjaUG opened 1 year ago

CodeNinjaUG commented 1 year ago
    app.js:26405 Uncaught TypeError: (0 , alga_js_array__WEBPACK_IMPORTED_MODULE_1__.paginate)(...) is not a function am getting this error

Originally posted by @CodeNinjaUG in https://github.com/tedirghazali/alga-js/issues/2#issuecomment-1322009995

tedirghazali commented 1 year ago

"Uncaught TypeError", I think this is because of the return value from paginate is null or nan, below this, its the code for that paginate function

const paginate = (fromArray, pageActive = 1, limitPerPage = 10) => {
  const newArray = Array.from(fromArray)
  const startPaginate = (Number(limitPerPage) * Number(pageActive)) - (Number(limitPerPage) - 1)
  const endPaginate = Number(limitPerPage) * Number(pageActive)

  return newArray.slice(startPaginate - 1, (endPaginate <= newArray.length) ? endPaginate : newArray.length)
}
CodeNinjaUG commented 1 year ago

yes i figured it out ... import * as array from 'alga-js/array' array.paginate(arrayOfObjects, currentPage, limitPerPage) using vue 3 with composition api