Data Render, but i can't sort it.

Data Render, but i can't sort it.

s33ks33k Posts: 4Questions: 1Answers: 0

Hey, guys,
sorry for my bad english, but I have in problem and I can't manage to solve it.
I use the following code:

{ "data": null, "render": function ( data, type, row ) {
let sdate1 = new Date ();
let sdate2 = new Date (data.dexpired);
let smilli1 = sdate1.getTime();
let smilli2 = sdate2.getTime();

if (smilli2 > smilli1 && data.dconfirmed == null && data.ddeleted == null) {
return 'Open';
} else if (smilli2 < smilli1 && data.dconfirmed == null && data.ddeleted == null) {
return 'Overdue';
} else if (data.dconfirmed != null && data.ddeleted == null) {
return 'Confirmed';
} else if (data.ddeleted != null) {
return 'Closed';
}
return 'Error!';
}
},

Unfortunately, the columns can't be sorted or found afterwards.
I just want to fill a column and need the values from the data set only for the query.

Thank You.

Answers

  • s33ks33k Posts: 4Questions: 1Answers: 0

    I use Server-side processing btw.

  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    If you're using serverSide then it's the responsibility of the server-side scripts to do the sorting and filtering. The protocol is discussed here. Also see examples here.

    You only need serverSide if you have 10ks or records - if less, just let the client take care of it.

    Cheers,

    Colin

  • s33ks33k Posts: 4Questions: 1Answers: 0

    I thought the server side script only fetches the data?! All other columns can be sorted without problems. I think my problem is that I only return a string and no object "data". I use the server side script because I already have several 100k lines.

  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    Nope, the server-side script does everything - sorting, filtering, paging, etc - it only returns the data to be displayed, in the order expected. If serverSide is enabled, the client only displays what's returned. It would be worth looking at the links I posted above,

    Colin

  • s33ks33k Posts: 4Questions: 1Answers: 0

    I have now integrated all this into the server script. Which makes me wonder, how can I sort a column that does not refer to a column header?
    Or rather, how can I output text in a field that is not related to the database?
    Maybe: 'db' => null,?
    With the code below we sort by dlocked. But not by the string that is returned.

    array(
                'db'        => 'dlocked',
                'dt'        => 'status',
                'formatter' => function( $d, $row ) {
                    $dnow = strtotime(date('Y-m-d H:i:s'));
                    $dexpired = strtotime($row[24]);
    
                    if ($dexpired > $dnow && $row[25] == null && $row[26] == null){
                        return 'Open';
                    } elseif ($dexpired < $dnow && $row[25] == null && $row[26] == null){
                        return 'Expired';
                    } elseif ($row[25] != null && $row[26] == null){
                        return 'Confirmed';
                    } elseif ($row[26] != null){
                        return 'Deleted';
                    } else {
                        return 'Error';
                    }
                }
            ),
    
  • colincolin Posts: 8,661Questions: 0Answers: 1,449

    It might be easier to do that on the client-side, with columns.render - you can change the data to be anything there.

    Colin

Sign In or Register to comment.