Query - for Help and better solution

Query - for Help and better solution

k-georgek-george Posts: 9Questions: 2Answers: 0

**https://live.datatables.net/ciyuride/21/edit**:

At the above 'test case'

Add a content before the current text

only if the first row contains a 'specific word'.(there use '36' and another is '$2,')

It is working for the first page only.

So the query is

1- How to loop through the entire table ?

2- Whether the Javascript works well on all browsers (old and modern) ?

3- Any better method to tiny up the said Javascript ?

4- Unable to change the table cell values from the default values to check that what will happen if the same mentioned values '36' is available on two different column.

Looking forward for a solution.

george

Answers

  • kthorngrenkthorngren Posts: 22,325Questions: 26Answers: 5,134

    It is working for the first page only.

    When Datatables initializes it builds an internal data cache of all the table rows. Datatables removes all the rows from the DOM except those displayed on the current page. So Javascript and jQuery utilities only have access to find elements on the page displayed. Use Datatables APIs like rows().every() to access the table data.

    How to loop through the entire table ?

    Use rows().every(). Use row().node() to get the row's HTML node for the $(node).find('td')... statement.

    Unable to change the table cell values from the default values to check that what will happen if the same mentioned values '36' is available on two different column.

    Use Datatables API's like cell().data() to update the data. This way Datatables knows about the changes and updates it's data cache.

    Any better method to tiny up the said Javascript ?

    Instead of using $(document).ready() use initComplete to execute the code to update the cell styling. The Datatable might not be fully initialized when the $(document).ready() code executes.

    Move the $(document).ready() into a function for easier maintenance.

    See this updated example:
    https://live.datatables.net/vohiyelo/1/edit

    Kevin

  • k-georgek-george Posts: 9Questions: 2Answers: 0

    Hi,

        Thank you for the reply and information.
    

    Lack of knowledge in datatables

    unfortunately not yet succeed.

    if it is not consume too much time then can you demonstrate it ?

    george

  • kthorngrenkthorngren Posts: 22,325Questions: 26Answers: 5,134

    if it is not consume too much time then can you demonstrate it ?

    Did you see the example I posted?
    https://live.datatables.net/vohiyelo/1/edit

    I don't fully understand your solution requirements so the example may not reflect what you want but I think it reflects what you did in your code.

    Please post more specific questions so we can offer more complete help.

    Kevin

Sign In or Register to comment.