Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:28:01+00:00 2026-06-01T06:28:01+00:00

I want to establish some fixed rows in head of the datatable. This is

  • 0

I want to establish some fixed rows in head of the datatable.

This is my datatable settings:

var oTable = $('#transactions').dataTable( {
    "aaSorting": [ [0,'desc'] ],
    "bFilter": false,
    "bSort": true, 
    "aaSorting": [[3,'desc']], // default search colums
    //            "aaSortingFixed": [[3,'desc']],
    "bPaginate": true,
    "bProcessing": true,
    "sPaginationType": "full_numbers",
    "asStripeClasses": [ 'monitoring-table-new' ],
    "bAutoWidth": false,
    "aoColumns": [
        {   "sType": "custom",
            "sClass": "td-date-size-cell",
            "fnRender": function ( oObj, sVal ) {
                return '<div class="monitoring-head-new leadencolor"><div class="form-border"><span class="date"><em>' + sVal + '</em></span></div></div>';
            }
        },
        {   "sType": "custom",
            "sClass": "td-transaction-size-cell",
            "fnRender": function ( oObj, sVal ) {
                return '<div class="monitoring-head-new leadencolor"><div class="form-border"><span class="transaction"><em>' + sVal + '</em></span></div></div>';
            }
        },
        {   "sType": "custom",
            "sClass": "td-client-size-cell",
            "fnRender": function ( oObj, sVal ) {
                return '<div class="monitoring-head-new leadencolor"><div class="form-border"><span class="client"><div>' + sVal + '</div></span></div></div>';
            } 
        },
        {   "sType": "custom",
            "sClass": "td-value-size-cell",
            "fnRender": function ( oObj, sVal ) {
                return '<div class="monitoring-head-new leadencolor"><div class="form-border"><span class="value"><em>' + sVal + '</em></span></div></div>';
            }
        },
        {   "sType": "custom",
            "sClass": "td-status-size-cell",
            "fnRender": function ( oObj, sVal ) {
                return '<div class="monitoring-head-new leadencolor"><div class="form-border"><span class="status"><div>' + sVal + '</div></span></div></div>';
            }
        },
    ],
    "sAjaxSource": '<?php echo url_for('@test?sf_format=json'); ?>',  

} );

I have done in the following way:

   jQuery.fn.dataTableExt.oSort['custom-asc']  = function(x,y) {
        if (x.indexOf("MY VALUE") != -1) return -1; // keep this row at top
        if (y.indexOf("MY VALUE") != -1) return 1; // keep this row at top

        return ((x < y) ? -1 : ((x > y) ?  1 : 0));
    };

    jQuery.fn.dataTableExt.oSort['custom-desc'] = function(x,y) {
        if (x.indexOf("MY VALUE") != -1) return 1; // keep this row at top
        if (y.indexOf("MY VALUE") != -1) return -1; // keep this row at top

        return ((x < y) ?  1 : ((x > y) ? -1 : 0));
    };

This will keep in top position the rows which have “MY VALUE” in text. But the problem is that when I sort on other column, the “fixed” row is not remaining on top of the table.

Any solutions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:28:02+00:00Added an answer on June 1, 2026 at 6:28 am

    This is not easy, one thing you could do is mix your custom sorting with a custom datasource sorting tha customizes your datasource

    // var oTable;
    var onTopValues = new Array("Litige", "5410");
    
    /*  disable asc sorting for specific rows */
    jQuery.fn.dataTableExt.oSort['custom-asc']  = function(x,y) {
    
            if (isOnTop(x)) return -1; // keep this row at top
            if (isOnTop(y)) return 1; // keep this row at top
    
            return ((x < y) ? -1 : ((x > y) ?  1 : 0));
    };
    
    jQuery.fn.dataTableExt.oSort['custom-desc'] = function(x,y) {
            if (isOnTop(x)) return -1; // keep this row at top
            if (isOnTop(y)) return 1; // keep this row at top
    
            return ((x < y) ?  1 : ((x > y) ? -1 : 0));
    };
    
    function isOnTop(s) {
            // search for on top values
            for (var i = 0; i < onTopValues.length; i++) {
              if (s === onTopValues[i]) {
                return true; 
              }
            }
    
            return false;
    }
    //custom datasource
    $.fn.dataTableExt.afnSortData['custom-ontop'] = function  ( oSettings, iColumn )
    {
      var aData = [];
      //prepare the data
      $('td:eq('+iColumn+')',  oSettings.oApi._fnGetTrNodes(oSettings)).each(function(){
        //If the last column of this row should stay on top, return the value of the 
        //last row as datasource
        if(isOnTop($(this).closest('tr').find('td:last').text())){
           aData.push($(this).closest('tr').find('td:last').text());
        }else{
            //otherwise return this row as datasource
             aData.push($(this).text());
        }
      });
    
      return aData;
    };
    
    
    $(document).ready(function() {
    
              /* Apply custom classes to table headers */
            $.fn.dataTableExt.oStdClasses.sSortAsc = "custom_asc";
            $.fn.dataTableExt.oStdClasses.sSortDesc = "custom_desc";
    
    
      oTable = $('#transactions').dataTable({       
            "aoColumnDefs": [ { aTargets: [0,1,2,3], sType: "custom"}] ,
             "aoColumns": [
                    { "sSortDataType": "custom-ontop" },
                    { "sSortDataType": "custom-ontop" },
                    { "sSortDataType": "custom-ontop" },
                    { "sSortDataType": "custom-ontop" },
                    { "sSortDataType": "custom-ontop" }
                ],
            "aaSorting": [],
            "aaData": [
                [ "2012-01-2", "2", "Local <br>0312313213", 20, "Litige" ],
                [ "2012-03-22", "25", "Local <br>35313313213", 5540, "Valid" ],
                [ "2012-01-2", "2", "Local <br>0312313213", 10, "Valid" ],
                [ "2012-03-22", "25", "Local <br>35313313213", 5410, "Valid" ]
            ]
        });    
    });
    

    Basically you are still using your sorting function but you pass them a custom datasource that forces the values to stay on top. This assume that you are sorting on the last column, but you can add your logic to it.

    http://jsbin.com/eroyac/4/edit#preview

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some java-app, and i want to establish a connection to some https
i want to establish communication in some different application. all application has been developed
I want to establish whether my understanding to some basic C++ reference principles are
I want to establish a connection between my local machine and MySQL database server
I am building DB class, in the constructor I want to establish the connection
I have two classes and I want to establish a many-to-many assications, here is
I am very new to Shell/Bash but I want to use it to establish
I want to write some tests for views in a Django profile app. The
For some reason whenever I want to query data from the database I get
I'm testing Synapse and want to know how can I establish a secure connection.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.