Hoping to make the shift to ServerSide, but unsure of how to keep my formatting.

Hoping to make the shift to ServerSide, but unsure of how to keep my formatting.

MattDaneMattDane Posts: 2Questions: 1Answers: 0

Hey there. I'm using DataTables for a client to show nearly 4000 rows of data with row classes (colours), links and images included. Now, as the table is getting larger, it's becoming more and more of a strain on the browsers, and most of the time my client needs the data to be available and searchable much faster. Thing is, the manual is puzzling and I don't think that switching to ServerSide code is going to allow me to preserve the colour-coding and/or extras.

Take a look at this JSFiddle for example. This is a sample of some of our data.
http://jsfiddle.net/3y9fw8mw/9/

The code behind this basically loops through the database, creates each row and assigns a colour class based on the data's priority. The columns are also generated and shown depending on a settings switch, so the user seeing the table gets to choose which columns to see.

At the moment, I see no way to achieve all this via ServerSide processing. :c
Any ideas?

  • Matt

This question has an accepted answers - jump to answer

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    Answer ✓

    I decided to upload an example of my own server-side code. It was my first attempt, and I would probably do a few things differently (such as passing variables to the class and writing the query there instead of having a ton of huge queries in my controller).

    You could easily preserve your color coding by assigning the class in your query. I am assuming anyway that you can figure out which you'd need inside it. DT_RowClass is a class that will be assigned to each row in your table. Here is an example:

    $sql = "
        SELECT
            order_id,
            full_name,
            order_date,
            status,
            shipping_type,
            case priority
                WHEN 1 THEN 'red',
                WHEN 2 THEN 'orange',
                WHEN 3 THEN 'yellow',
            END AS DT_RowClass,
        FROM
            my_table
    ";
    
  • allanallan Posts: 61,683Questions: 1Answers: 10,100 Site admin

    Before you go fully server-side processing, you might want to consider using Ajax loaded data with deferred rendering enabled (example). That should be good speed wise up to around 50k records.

    However, for both Ajax loaded data (client-side processing) and server-side processing you will need to modify your Javascript a bit to add the various extras needed to your HTML.

    Firstly consider columns.render which can be used to add img tags and otherwise format the data.

    Then for your cell / row colours you can use columns.createdCell and createdRow to add a class to the node that DataTables created.

    Thanks,
    Allan

  • MattDaneMattDane Posts: 2Questions: 1Answers: 0

    Thanks ignignokt and allan for your suggestions and examples. I'm going to go ahead and go full server-side.

    The example that ignignokt provided I can understand better and seems to focus more on getting php to do things, rather than the deferred rendering method which looks like it'll need a lot of javascript in order to create links and images within the table (which I'm not so clued up on).

    Cheers again for the speedy responses, much appreciated!
    I'll be sure to ask another question if I get stuck.

    • Matt
This discussion has been closed.