logo
down
shadow

Datatables generate column and get row id Server-side


Datatables generate column and get row id Server-side

By : Tien Nguyen
Date : November 22 2020, 02:42 PM
it should still fix some issue You need to use the render property:
code :
"render": function ( data, type, full) {
            return "<button type='button' class='btn btn-success' data-id=" + full[3] + ">PAY</button>";
    }


Share : facebook icon twitter icon
jquery datatables server side - filter column on top

jquery datatables server side - filter column on top


By : Fede Ls
Date : November 01 2020, 01:05 PM
I hope this helps you . SOLUTION Add extra row in thead for search filters with the same amount of columns. Use orderCellsTop to instruct plugin to use top row for sorting. Use the code below to create filters and attach event handler.
code :
// Setup - add a text input to each header cell
$('#example thead tr:eq(1) th').each( function () {
    var title = $('#example thead tr:eq(0) th').eq( $(this).index() ).text();
    $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} ); 

var table = $('#example').DataTable({
    orderCellsTop: true
});

// Apply the search
table.columns().every(function (index) {
    $('#example thead tr:eq(1) th:eq(' + index + ') input').on('keyup change', function () {
        table.column($(this).parent().index() + ':visible')
            .search(this.value)
            .draw();
    });
});
Using Variable to DataTables Server-Side Column value Formatter

Using Variable to DataTables Server-Side Column value Formatter


By : Amol
Date : March 29 2020, 07:55 AM
may help you . I want to pass PHP function on each cell of DataTables via Server-side Formatter, but PHP Function is dynamic. Here is example code: , I have solved the issue by using the PHP Closures:
code :
$func_apply = $_GET['function_name']; // trim | strip_tags | md5 | ucwords

$columns[] = array(
'db'        => $field,
'dt'        => '3',
'formatter' => function( $d, $row ) use ($func_apply) {
            return $func_apply($d);
        }
);
How to use DataTables server side column ordering?

How to use DataTables server side column ordering?


By : chiran
Date : March 29 2020, 07:55 AM
it helps some times I would suggest to use the datatables.mvc5 package which is a datatables model binder to controller implemented by Stefan Nuxoll.
Your action would look like:
code :
public ActionResult Get([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)
{

  IQueryable<asset> query = DbContext.Assets;

  // Sorting
  var sortedColumns = requestModel.Columns.GetSortedColumns();
  var orderByString = String.Empty;

  foreach (var column in sortedColumns)
  {
     orderByString += orderByString != String.Empty ? "," : "";
     orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc");
  }

    query = query.OrderBy(orderByString == string.Empty ? "BarCode asc" : orderByString);

   var data = query.Select(asset => new
   {
      AssetID = asset.AssetID,
      BarCode = asset.Barcode,
      Manufacturer = asset.Manufacturer,
      ModelNumber = asset.ModelNumber,
      Building = asset.Building,
      RoomNo = asset.RoomNo,
      Quantity = asset.Quantity
   }).ToList();

 return Json(new DataTablesResponse(requestModel.Draw, data, filteredCount, totalCount), JsonRequestBehavior.AllowGet);

}
$('#assets-data-table').DataTable({
    "serverSide": true,
    "processing": true,
    "ajax": {
        "url": "@Url.Action("Get","Asset")"
    },
    "columns": [
        { "title": "Bar Code", "data": "BarCode", "searchable": true },
        { "title": "Manufacturer", "data": "Manufacturer", "searchable": true },
        { "title": "Model", "data": "ModelNumber", "searchable": true },
        { "title": "Building", "data": "Building", "searchable": true },
        { "title": "Room No", "data": "RoomNo" },
        { "title": "Quantity", "data": "Quantity" }
    ],
    "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
});
Datatables server side processing and column alias

Datatables server side processing and column alias


By : Charles
Date : March 29 2020, 07:55 AM
To fix this issue Yes. I actually just struggled with this issue myself. Because the JSON output is determined through counting the amount of columns in the array, and because of the imploding array, you have to add your column alias to $sQuery instead of the $aColumns array. So you'll actually have one less column in your $aColumns array than you'll need. For example, in mine, I needed an alias called total created from multiplying price and qty. So I put all my unaliased columns in the $aColumns array, like this:
DataTables Server-Side processing, generate a link in a column with two variables

DataTables Server-Side processing, generate a link in a column with two variables


By : Youssef Belmehdi
Date : March 29 2020, 07:55 AM
shadow
Privacy Policy - Terms - Contact Us © animezone.co