jQuery UI Widgets Forums Angular row.boundindex in createwidget not correct

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  Hristo 1 month, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • ilywanzi
    Participant

    Hi, I am using createwidget method to create some buttons inside one grid cell, but I found the row.boundindex from createwidget is not correct.
    For example, there are 100 rows in grid, but because of the grid height, only the first 20 rows rendered. When I click the button and print their index in console, it is correct.
    But if I scroll down, click a button in 40th row, will print the wrong index number in console because this row is the 20th row in the grid now.
    Please check this example and replace the columns with the code below, you will understand what I am talking about. When you scroll down, you can see the issue from the button index.
    Please let me know if any way I can fix this issue. Thanks.

    
    columns: any[] =
        [
          {
            text: 'Picture', datafield: 'firstname', width: 100,
            createwidget: (row: any, column: any, value: string, htmlElement: HTMLElement): void => {
              const container = document.createElement('div');
              const btn = document.createElement('button');
                  btn.innerHTML = 'btn'+row.boundindex;
                  container.appendChild(btn);
                  btn.addEventListener('click', () => {
                    console.log('row index', row.boundindex);
                  });
              htmlElement.appendChild(container);
    
            },
            initwidget: (row: number, column: any, value: any, htmlElement: HTMLElement): void => { }
          },
          { text: 'Name', datafield: 'name', width: 200 },
          { text: 'Title', datafield: 'title', width: 200 },
          { text: 'Country', datafield: 'country' }
        ];
    
    • This topic was modified 1 month, 2 weeks ago by  ilywanzi.

    Hristo
    Participant

    Hello ilywanzi,

    You should implement the initwidget callback for this purpose.
    The createwidget callback is for the first rendering of the rows.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com


    ilywanzi
    Participant

    Hi Hristo, could you please provide a sample code for that? Thanks.


    Hristo
    Participant

    Hello ilywanzi,

    You could find the source of all demos in the download package.
    Also, with each one demo on our site, you could find the tabs with the source of the particular demo.
    Please, take a look at this demo.
    I hope this will help.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.