“suitlet max lines and paging” 可以翻译为 “suitlet 最大行数和分页”。

huangapple go评论75阅读模式
英文:

suitlet max lines and paging

问题

我需要创建一个suitlet,根据条件显示像发票、账单、日记账等交易记录...
目标是创建一个自定义的总账匹配页面,其中包含许多结果。
我知道搜索最多可以返回4000个结果。
我还知道如果页面上的结果超过500个,用户的笔记本电脑可能会冻结。
是否有办法进行分页,让用户点击"下一页"或"上一页"按钮,以每次加载500个结果?
我看到有一种使用分页和将页面保存在参数中的方法,但这并不合适,因为之后的目标是触发一个计划任务或映射/减少脚本来处理所选内容。
或者也许使用缓存来保存所选内容?
我想创建一种单页应用程序(SPA)。

英文:

I need to create a suitlet where according to criteria, I will show transactions like invoice, bill, journal, ...
The Goal is to make a custom GL matching page with many results.
I know that a search can return maximum 4000 results.
I also know that the laptop from the user can freeze if the number of results is above 500 on the page.
Is there a way to make paging and let the user click on a next or before button to load 500 results by 500 results?
I saw that there was a way with paging and saving the page in the parameter but it isn't ok because the goal after is to trigger a scheduled or map/reduce script to process the selection.
Or maybe use cache to save the selected one?
I wanted to make a sort of SPA

答案1

得分: 0

你可以通过使用RESTlets以及传统的HTML、CSS和JavaScript来在客户端执行此操作。

要实现这一点,您将需要一个Suitelet,根据传递的参数返回HTML或返回JSON。为了使其工作,您将需要在客户端上使用JavaScript从提供HTML的相同Suitelet中获取数据,以避免出现CORS等问题,并使用API调用的结果和JavaScript来更新DOM。您还可以使用这种方法来触发与获取分页保存搜索结果类似的Map/Reduce脚本。

这有点复杂,因为您必须从头开始做所有事情,而不是使用NetSuite的本机serverWidet模块,但以这种方式操作可以让您构建任何您想要的东西。

示例RESTlet的获取函数

    const get = ({page: pageIndex}) => {
        const PAGE_SIZE = 50; // 将此更改为您想要的页面大小,最多为500
        
        // 添加其他过滤器和列等,以适合您的用例
        const ss = search.create({
            type: "employee", // 您想要的记录类型
        });
        
        const pagedResults = ss.runPaged({pageSize: PAGE_SIZE});

        // 使用此来了解可以迭代的可用页数
        const numPages = Math.ceil(pagedResults.count / PAGE_SIZE);
        
        let page = pagedResults.fetch({index: pageIndex});

        const data = [];
        page.data.forEach((result) => {
            // 构建您要从RESTlet返回的数据
            data.push(result.id);
        });
        
        return JSON.stringify({
            data,
            currentPage: pageIndex,
            pageCount: numPages,
        });
    }

示例用于管理所选行及其关联数据状态的客户端JavaScript

      const selectedItems = [];
      let currentPageIndex = 0; // 每当更改页面时都必须更新此值
      
      // 应该添加类似的事件监听器到复选框元素,以允许您存储有关所选行的信息
      const handleCheckboxCheck = (e) => {
        const rowIdx = 1; // 从DOM中获取此值
        if (e.target.checked) {
          // 将所选项添加到状态中
          selectedItems.push({
            data: {
              /** 想要记录的信息放在这里 */
            },
            rowIdx,
            pageIdx: currentPageIndex,
          });
        } else {
          // 从状态中删除所选项
          const idx = selectedItems.findIndex(
            (v) => v.rowIdx == rowIdx && v.pageIdx == currentPageIndex
          );
          selectedItems.splice(idx, 1);
        }
      };
英文:

You can do this client side by utilizing RESTlets and good old fashioned HTML CSS and JavaScript.

To do this, you will have to have a suitelet that will return HTML when depending on the parameters it's passed or return JSON. For this to work you will have to use JavaScript running on the client to fetch data from the same Suitelet that the HTML is served on to avoid any issues with CORS, etc. and update the DOM using the results of the API call and JavaScript. You can also use this method to trigger your Map/Reduce script in the same way you would get paged saved search results.

It's kind of complicated because you have to do everything from scratch instead of using NetSuite's native serverWidet module, but doing it this way will allow you to build whatever you want.

example restlet get function

    const get = ({page: pageIndex}) => {
        const PAGE_SIZE = 50; // change this to be whatever page size you want to up to 500
        
        // add other filters and columns, etc. that make sense for your use case
        const ss = search.create({
            type: "employee", // w/e record type you want here
        });
        
        const pagedResults = ss.runPaged({pageSize: PAGE_SIZE});

        // use this to know what pages are available to iterate over 
        const numPages = Math.ceil(pagedResults.count / PAGE_SIZE);
        
        let page = pagedResults.fetch({index: pageIndex});

        const data = [];
        page.data.forEach((result) => {
            // build your data you want to return from the restlet
            data.push(result.id);
        });
        
        return JSON.stringify({
            data,
            currentPage: pageIndex,
            pageCount: numPages,
        });
    }

example javascript used on the client to manage the state of what rows are selected and their associated data

      const selectedItems = [];
      let currentPageIndex = 0; // this will have to be updated whenever you change pages
      
      // a similar event listener should be added to your checkbox elements to allow you 
      // to store information about the rows selected
      const handleCheckboxCheck = (e) => {
        const rowIdx = 1; // get this from the dom
        if (e.target.checked) {
          // add the selected to the state
          selectedItems.push({
            data: {
              /** information you would like to keep record of goes here */
            },
            rowIdx,
            pageIdx: currentPageIndex,
          });
        } else {
          // remove the selected from state
          const idx = selectedItems.findIndex(
            (v) => v.rowIdx == rowIdx && v.pageIdx == currentPageIndex
          );
          selectedItems.splice(idx, 1);
        }
      };

huangapple
  • 本文由 发表于 2023年3月3日 20:15:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626965.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定