Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all 79589 articles
Browse latest View live

Inject content to or produce 'generated content for a column' for Ajax-sourced data.

$
0
0

Hi,

  1. I have different tables on different pages of an asp net mvc project. Each table has its own action buttons as the last column's data, produced with view engine and unobtrusive-Ajax helper. That works pretty well.

  2. To reduce code amount, I've used html5 data attributes for each table and produced a single JS code in one file to initialize all DataTables when the containing page is loaded. And implemented the DataTable as Ajax-soruced according to a request-URL of HTML table's data attribute.

    <script>
            var dtList = Array.prototype.slice.call($('table'));
                        dtList.forEach(function (el, index) {
                            var dt = 'dt' + index,
                                dtType = $(el).data('dttype'),
                                dtAjaxUrl = $(el).data('request-url'),
                                grouping = $(el).data('datasrc') !== null && $(el).data('datasrc') !== undefined ? true : false,
                                grEnding = $(el).data('endrendering'),
                                grCol = $(el).data('datasrc'),
                                grEndCol = $(el).data('datasrc'),
                                grCtx = grouping ? grEnding ? { "endRender": function (rows, group) { return grEnder(rows, group, dt, dtType); }, "dataSrc": grCol } : { "dataSrc": grCol } : null,
                                $dt = $(el).DataTable({
                                    "bProcessing": true,
                                    "bDeferRender": true,
                                    "sAjaxSource": dtAjaxUrl,
                                    "columnDefs": [{
                                        "targets": -1,
                                        "data": null,
                                        "defaultContent": '<button class="btn btn-sm btn-primary" onclick="">Edit</button><button class="btn btn-sm btn-danger" onclick="">Remove</button>'
                                    }],
                                    dom: "lBfrtip",
                                    rowGroup: grCtx,
                                    "bAutoWidth": true,
                                    language: // not included for brevity
                                    buttons: // not included for brevity
                                });
    </script>
    
  3. The question is, after I've changed my code to get table data from Ajax calls instead of implementing it manually in the view part, I've lost flexibility to design each table's last column's data according to actions related. Is there any option or way to include manually produced content (buttons) as the last column data after Ajax result. I've used 'generated content for a column' in my example, but what I esp. ask for is to inject an unobtrusive-Ajax form content, which is produced within a view, to DataTable's each row's last column, or any better approach.

I am new to DataTables and generally new to web design concepts. Apologies for any mistakes. Thanks...


Using Responsive >=2.x & ColVis - Show Hidden Columns In Child Row?

$
0
0

I found the following question and relative answer on Stack Overflow: https://stackoverflow.com/a/32993719/2110294

Which points to a previous discussion on these forums: https://datatables.net/forums/discussion/29860/using-colvis-button-with-responsive-table-disables-hidden-columns

In this we find the following example: http://live.datatables.net/poqoyezo/1/edit

In this example, when a column is hidden / shown by ColVis it is added or removed from the child row.

Bumping the dependencies to the latest versions shows that this functionality is no longer the same.

Reverting the Responsive dependency to 1.0.7 shows that it something that changed between this version and version 2 which created these changes.

Is it possible that we can recreate this behavior with version >=2.0.0 of Responsive, could anyone share an updated example of this?

Many thanks.

EDIT: Here is a test case: http://live.datatables.net/femudeda/1/edit

Table Header not resizing

$
0
0

Hey Guys,

http://live.datatables.net/yeqazuze/7 In this example it's showing 2 headers (no sure why). However, on my system. It's showing the top header that doesn't seem to horizontal scroll. If you make the window smaller and scroll right. You'll see it's not fixed on the columns.

Thanks again

Inline editor - Dropdown will not update database

$
0
0

I have a datatable that contains the contents of 3 joined tables, here is the server side:

Editor::inst( $db, 'enqitem', 'enqitemid')
->fields(
    Field::inst( 'stock.salmasid' ),
    Field::inst( 'stock.partnum' ),
    Field::inst( 'stockitem.salsubid' ),
    Field::inst( 'stockitem.condition1' ),
    Field::inst( 'stockitem.supplier' ),
    Field::inst( 'enqitem.enqitemid' ),
    Field::inst( 'enqitem.cost' ),
    Field::inst( 'enqitem.sale' ),
    Field::inst( 'enqitem.qty' ),
    Field::inst( 'enqitem.linedisc' ),
    Field::inst( 'enqitem.leadtime' )           
)
->leftJoin('stock', 'stock.salmasid', '=', 'enqitem.itemmasid')
->leftJoin('stockitem', 'stockitem.salsubid', '=', 'enqitem.itemid')
->where('enqitem.enqnr',141316)
->debug( true )
->process( $_POST )
->json();

And here is the editor:

let editor = new $.fn.dataTable.Editor( {
    ajax: {
        url: "ajax.php",
        type: "POST"
    },
     
    table: "#dataTableSites",
    fields: [{
            label: "ID:",
            name: "stock.salmasid",
            type: "hidden"
        },{
            label: "ID:",
            name: "stockitem.salsubid",
            type: "hidden"
        },{
            label: "ID:",
            name: "enqitem.enqitemid",
            type: "hidden"
        },{
            label: "Part Number:",
            name: "stock.partnum"
        },{
            label: "Condition:",
            name: "stockitem.condition1",
            type: "select",
            options: [
                { label: "New", value: "New" },
                { label: "Used", value: "Used" },
                { label: "Repair", value: "Repair" }
            ]
        },{
            label: "Supplier:",
            name: "stockitem.supplier",
            type: "select"
        },{
            label: "Cost:",
            name: "enqitem.cost"
        },{
            label: "Sale:",
            name: "enqitem.sale"
        },{
            label: "Qty:",
            name: "enqitem.qty"
        },{
            label: "Disc:",
            name: "enqitem.linedisc"
        },{
            label: "Delivery Time:",
            name: "enqitem.leadtime"
        }
    ]
} );

It is set to edit inline like so:

            $('#dataTableSites').on( 'click', 'tbody td:not(:first-child)', function (e) {
                editor.inline( this, {
                    onBlur: 'submit'
                } );
            } );

If I change a the sale value (which is an inputbox) I can see in the debug the following:

{"query":"UPDATE  `enqitem` SET  `sale` = :sale WHERE `enqitem`.`enqitemid` =....

However when I change the condition (which is a dropdown) the database never updates. In fact the debug doesn't contain an UPDATE statement at all, only a SELECT.

Does the dropdown need to be set up differently?

Uncaught TypeError: extender is not a function

$
0
0

I'm trying to implement DataTable editor in my application and currently facing issue> Uncaught TypeError: extender is not a function whenonBlur: 'submit'is called.
When I tried to debug the lib I found out that there is no function _fnExtend which makes var extender = $[O12][J3p][u12][o3p]; extender undefined.

Inline editor only updates the host table

$
0
0

I have a simple table using a left join:

        Editor::inst( $db, 'enqitem', 'enqitemid')
        ->fields(
            Field::inst( 'salstkitem.salsubid' ),
            Field::inst( 'salstkitem.condition1' ),
            Field::inst( 'enqitem.cost' )          
        )
        ->leftJoin('salstkitem', 'salstkitem.salsubid', '=', 'enqitem.itemid')
        ->where('enqitem.enqnr',141316)
        ->debug( true )
        ->process( $_POST )
        ->json();

In the editor, I have hidden the primary key of the non-host table:

            editor = new $.fn.dataTable.Editor( {
                ajax: "datatables.php",
                table: "#example",
                fields: [{
                        name: "salstkitem.salsubid",
                        type: "hidden"
                     },{
                        label: "Condition:",
                        name: "salstkitem.condition1"
                    },{
                        label: "Cost:",
                        name: "enqitem.cost"
                    }
                ]
            });

I've set it to be editable inline:

            $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
                editor.inline( this, {
                    onBlur: 'submit'
                } );
            });

When I edit inline, the cost updates successfully, as it's a member of the host table. However condition1 will not update.
If I select the EDIT button, both fields update successfully.

This issue is purely for inline editing.

Does anyone have any idea why?
The debug suggests it isn't trying to update at all. It is purely a SELECT query.

Dealing with passwords

$
0
0

~~Hi all!
I cant find a good tutorial with dealing with passwords and editor.

I want to use MD5() for insert in the db. I dont know how to do this!
I already found out to use a set- or getformatter - but i dont know how to do this with md5().

I have the following code and it works fine... but if I insert the following code I get an error:

    ->on( 'preEdit', function ( $e, $id, $values ) {
        if ( $values['WEBUPusers.login_pwd'] === '' ) {
            $e->field( 'WEBUPusers.login_pwd' )->set( false );
        }
    } )
/ Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'WEBUPusers' )    
    ->fields(
        Field::inst( 'WEBUPusers.name' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'A name is required' ) 
            ) ),
        Field::inst( 'WEBUPusers.vorname' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'A first name is required' ) 
            ) ),
        Field::inst( 'WEBUPusers.abteilung' )
           ->options( Options::inst()
                    ->table( 'WEBUPdepartments' )
                    ->value( 'id' )
                    ->label( 'caption' )
                ),
        Field::inst( 'WEBUPdepartments.caption' ),
        Field::inst( 'WEBUPusers.login_username' ),        
        Field::inst( 'WEBUPusers.login_pwd' ),        
    )
    ->leftJoin( 'WEBUPdepartments',     'WEBUPdepartments.id',  '=', 'WEBUPusers.abteilung' )
    ->where( function ( $q ) use ( $cid ) {
        $q->where( 'cid', $cid );
    } )    
    ->on( 'preEdit', function ( $e, $id, $values ) {
        if ( $values['WEBUPusers.login_pwd'] === '' ) {
            $e->field( 'WEBUPusers.login_pwd' )->set( false );
        }
    } )
    ->process( $_POST )
    ->json();
?>  

Please help!~~

Datatablet Pictures do not appear after moving to the next page

$
0
0

1-) Datatable Settings

    $("#markamodal_listesi").DataTable({
        "responsive": true,
        "bFilter": true,
        "paging": true,       
        "info": true,
        "language": {
            "url": "https://cdn.datatables.net/plug-ins/1.10.16/i18n/Turkish.json"
        },
        "columnDefs": [
            {"width": "20%", "targets": 0}, 
            {"width": "20%", "targets": 1},
            {"width": "20%", "targets": 2},
            {"width": "20%", "targets": 3},
            {"width": "10%", "targets": 4},
            {"width": "10%", "targets": 5}
        ]
    });

2-)

function markaModalTablosuDoldur(rows) {
        markaModalTablosu.clear().draw();
        for (var index in rows) {
            var data = rows[index];

            markaKodResimGetir(data["markaKodu"]);

            var durum;
            if (data["durum"] === "Aktif") {
                durum = "<span class='label label-success'><b>AKTİF</b></span>";
            } else {
                durum = "<span class='label label-danger'><b>PASİF</b></span>";
            }

            markaModalTablosu.row.add([
                data["markaSiraNo"],
                "<img id='resimMarka" + data["markaKodu"] + "'    width='150' height='100' />",
                data["markaKodu"],
                data["markaAdi"],
                durum,
                "<button  class='btn btn-danger mr-3 markasil-btn'  data-markaKodu='" + data["markaKodu"] + "'> <i class='fa fa-trash-o'></i></button>"
              + "<button class='btn btn-warning markaduzenle-btn '  data-markaKodu='" + data["markaKodu"] + "'><i class='fa fa-edit'></i></button>"
            ]);



        }
        markaModalTablosu.draw();
    }

3-)

function markaKodResimGetir(markaKodu) {
                    $.ajax({
                        url: "/networks/webapi/resimYukle/resimGoster/marka/" + markaKodu,
                        type: "GET",
                        success: function (data, textStatus, jqXHR) {

                            //var degerAl = data[0].resimAdres.toString();
                            if (data !== "") {
                                $('#resimMarka' + markaKodu).attr('src', '/resimler/marka/' + markaKodu + "/" + data.resimAdres);
                                $('#resimMarka' + markaKodu).attr('data-src', '/resimler/marka/' + markaKodu + "/" + data.resimAdres);
                            } else {
                                $('#resimMarka' + markaKodu).attr('src', 'plugins/images/resimYok.gif');
                                $('#resimMarka' + markaKodu).attr('data-src', 'plugins/images/resimYok.gif');
                            }

                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            swal("HATA", "Marka resim getirilirken hata oluştu", "error", {button: "Tamam"});
                        }
                    });
                }

Can you help me please...


Datatable Editor error on blur

$
0
0

Hi

I have setup a datatable with an inline editor. This is for data collection only and has no ajax calls.

On one specific cell I want to format the data (and then eventually process further).

So I have setup the editor, databable, callback and the function that does the actual processing (code is below).

Everything works ok until I try resetting the cell value. I get the following error:

Any help would be appreciated.

Thanks

Dov

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handler?
    at g (https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-flash-1.5.4/b-html5-1.5.4/b-print-1.5.4/cr-1.5.0/fc-3.2.5/fh-3.1.4/kt-2.5.0/r-2.2.2/rg-1.1.0/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.min.js:49:89)
    at da (https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-flash-1.5.4/b-html5-1.5.4/b-print-1.5.4/cr-1.5.0/fc-3.2.5/fh-3.1.4/kt-2.5.0/r-2.2.2/rg-1.1.0/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.min.js:49:311)
    at s.<anonymous> (https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-flash-1.5.4/b-html5-1.5.4/b-print-1.5.4/cr-1.5.0/fc-3.2.5/fh-3.1.4/kt-2.5.0/r-2.2.2/rg-1.1.0/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.min.js:144:308)
    at s.data (https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-flash-1.5.4/b-html5-1.5.4/b-print-1.5.4/cr-1.5.0/fc-3.2.5/fh-3.1.4/kt-2.5.0/r-2.2.2/rg-1.1.0/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.min.js:130:3)
    at Editor.edit (http://localhost:8090/resources/Editor-1.8.0/js/dataTables.editor.js:6859:9)
    at Editor._dataSource (http://localhost:8090/resources/Editor-1.8.0/js/dataTables.editor.js:4873:13)
    at Editor._submitSuccess (http://localhost:8090/resources/Editor-1.8.0/js/dataTables.editor.js:5941:11)
    at http://localhost:8090/resources/Editor-1.8.0/js/dataTables.editor.js:5766:9
    at Editor._submitTable (http://localhost:8090/resources/Editor-1.8.0/js/dataTables.editor.js:5833:2)
    at Editor._submit (http://localhost:8090/resources/Editor-1.8.0/js/dataTables.editor.js:5762:13)
//Editor Definition

  receiptEditor = new $.fn.dataTable.Editor({
    table: "#receiptTable",
    fields: [
      {
        label: "Tools",
        name: "tools"
      },
      {
        label: "ledger_type",
        name: "ledger_type",
        type: "select",
        options: lineTypeOptions
      },
      {
        label: "Description",
        name: "description"
      },
      {
        label: "AccountName",
        name: "accountName",
        id: "receiptCustomer"
      },
      {
        label: "CustomerReference",
        name: "customerReference"
      },
      {
        label: "Note",
        name: "note"
      },
      {
        label: "LineReference",
        name: "lineReference"
      },
      {
        label: "ReceiptAmount",
        name: "amount"
      },
      {
        label: "NoteButton",
        name: "noteButton"
      },
      {
        label: "Icons",
        name: "icons"
      },
      {
        label: "Remove",
        name: "remove"
      },
      {
        label: "CustomerId",
        name: "customerId"
      },
      {
        label: "LineNumber",
        name: "lineNumber"
      }
    ]
  });


//Setup Inline editing

$('#receiptTable').on( 'click', 'tbody td', function (e) {
    receiptEditor.inline();
  });

//Datable instance

  rctTable = $("#receiptTable").DataTable({
    columnDefs: [
      { className: "tools", targets: [0] },
      { className: "ledgerType", targets: [1] },
      { className: "receiptDescription", targets: [2] },
      { className: "receiptCustomer", targets: [3] },
      { className: "receiptCustomerReference", targets: [4] },
      { className: "receiptNote", targets: [5] },
      { className: "receiptLineReference", targets: [6] },
      { className: "receiptAmount", targets: [7] },
      { className: "receiptAllocated", targets: [8] },
      { className: "receiptOnAccount", targets: [9] },
      { className: "receiptCustomerId", targets: [13] },
      { className: "receiptLineNumber", targets: [14] }
    ],
    dom: "Brt",
    columns: [
      {
        data: "tools",
        render: function(data, type, row) {
          return "<i id='transactionsWindow' class='fas fa-receipt transactionsWindow iconHidden'></i>"; // <i id='receiptBlueCircle' class='fas fa-dot-circle receiptBlueCircle blueIcon'></i>
        }
      },
      {
        data: "ledger_type",
        render: function(data, type, row) {
          return lineTypeOptions[data - 1].label;
        }
      },
      {
        data: "description",
        render: function(data, type, row) {
          return receiptDescription;
        }
      },
      {
        data: "accountName"
      },
      {
        data: "customerReference"
      },
      {
        data: "note"
      },
      {
        data: "lineReference"
      },
      {
        data: "amount",
        classname: "receiptAmount"
      },
      {
        data: "allocated",
        classname: "receiptAllocated",
        render: function(data, type, row) {
          return "0.00";
        }
      },
      {
        data: "onAccount",
        classname: "receiptOnAccount",
        render: function(data, type, row) {
          return "0.00";
        }
      },
      {
        data: "noteButton",
        render: function(data, type, row) {
          return "<i class='fas fa-pencil-alt noteButton' style='text-align:center; width:1%'></i>";
        }
      },
      {
        data: "icons",
        render: function(data, type, row) {
          return "<i class='fas fa-plus plusButton table-add' style='text-align:left; width:1%'></i>";
        }
      },
      {
        data: "remove",
        render: function(data, type, row) {
          return "<i class='fas fa-times table-remove' style='text-align:center; width:1%'></i>";
        }
      },
      {
        data: "customerId"
      },
      {
        data: "lineNumber"
      }
    ],
    ordering: false,
    keys: {
      columns: ':not(:first-child)',
      keys: [ 9 ],
      editor: receiptEditor,
      editOnFocus: true
    },
    select: {
      select: true,
      style: "single",
      selector: "td:first-child",
      blurable: true
    },
    buttons: [
      {
        extend: "remove",
        editor: receiptEditor
      }
    ]
  });


//Callback on blur of receiptAmount cell

  $("#receiptTable").on(
    "focusout",
    ".receiptAmount",
    function() {   
      receiptAmountChanged(this);
    }
  );

//function called by blur Callback

  function receiptAmountChanged(current){

  var rowIndex = rctTable.row( rctTable.cell(current).index() ).index()
  
  var receiptAmount = rctTable.cell(current).data();
  receiptAmount = displayAsMoney(receiptAmount);

  rctTable.cell(current).data(receiptAmount).draw();

  };

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

How can I use editor.dependent() to get a single value for a field instead of a select?

$
0
0

I usually use editor.dependent() to get a value from a list box:

// JS file
...
{
    label: "Provincia",
    name: "contatti.cont_prov",
    type: "select"
},          
{
    label: "Località",
    name: "contatti.cont_loc",
    type: "select"
},
{
    label: "CAP",
    name: "contatti.cont_cap",
    type: "select"

},
...
clientiEditor.dependent( 'contatti.cont_prov', 'php/filtro_localita.php' ); 
clientiEditor.dependent( 'contatti.cont_loc', 'php/filtro_cap.php' );
...
// PHP file: filtro_localita.php
<?php
include( "DataTables.php" );

$comuni = $db
    ->select( 'comuni', ['com_nome as value','com_nome as label']
        ,['com_prov' => $_REQUEST['values']['contatti.cont_prov']] )
    ->fetchAll();

echo json_encode( [
    'options' => [
        'contatti.cont_loc' => $comuni
    ]
] );
// PHP file: filtro_cap.php
<?php
include( "DataTables.php" );

$cap = $db
    ->select( 'comuni', ['com_cap as value','com_cap as label']
        ,['com_nome' => $_REQUEST['values']['contatti.cont_loc']] )
    ->fetchAll();

echo json_encode( [
    'options' => [
        'contatti.cont_cap' => $cap
    ]
] );
?>

But how can I get a single value for the contatti.cont_cap field instead of a list box?
I tried to write:

// JS file
...
{
    label: "Provincia",
    name: "contatti.cont_prov",
    type: "select"
},          
{
    label: "Località",
    name: "contatti.cont_loc",
    type: "select"
},
{
    label: "CAP",
    name: "contatti.cont_cap"

},

and I modified the file filtro_cap.php in this way:

<?php
include( "DataTables.php" );

$cap = $db
    ->select( 'comuni', ['com_cap']
        ,['com_nome' => $_REQUEST['values']['contatti.cont_loc']] )
    ->fetchAll();

echo json_encode( $cap );
?>

the php file returns (for example):

[{"com_cap":"92100"}]

but my field is: contatti.cont_cap...
how should i do?

Thanks for your help,
Giuseppe

Page length not working when change datatables parameter

$
0
0

This is probably something very simple, but I am new to this, and have not been able to find answer on here.

Using Datatables with Bootstrap4 and PHP.

I am having problems getting table to display default number of rows (10).

I want to disable ability to change page length, but the moment I add any parameters to the Datatables function it expands to the number of records in the table.

The Head section contains:

        <link href="css/bootstrap.css" rel="stylesheet" id="bootstrap-css">
        <link href="css/dataTables.bootstrap4.min.css" rel="stylesheet" id="bootstrap-css">
        <link rel = "stylesheet" type = "text/css" href = "css/jquery.dataTables.min.css" />

        <link href="css/all.css" rel="stylesheet"  type="text/css">
        <script src="js/bootstrap.min.js"></script>
        <script src="js/jquery.min.js"></script>

At the base of the Body section

        <script src = "js/jquery-3.1.1.js"></script>
        <script src = "js/bootstrap.js"></script>
        <script src = "js/script.js"></script>
        <script src = "js/jquery.dataTables.min.js"></script>
        <script src = "js/dataTables.bootstrap4.min.js"></script>

and the function

           $(document).ready(function () {
             $('#table').DataTable({
             "paging": false,
             "lengthChange": false,
              "pageLength": 10
                });
           });

Date is collected via PHP

                    <tbody>
                        <?php
                        $query = $conn->query("SELECT * FROM `memberdetails` ORDER BY `lastname`, `firstname` ASC ") or die(mysqli_error());
                        while ($f_query = $query->fetch_array()) {
                            ?>
                            <tr>
                                <td><?php echo $f_query['firstname'] ?></td>
                                <td><?php echo $f_query['lastname'] ?></td>
                        </tr>
                        <?php
                    }
                    ?>
                    </tbody>

If I remove all the items in the DataTable function the default table form (10 rows, page length change dropdown, and search box) is shown.
If I just have the paging:false line it displays the table with search box, no dropdown, but all 200 records.
Adding any other item (e.g. pagelength) shows the full table, but with no search or dropdown.

Thanks for feedback

Value from a selected Item (PHP + JS)

$
0
0

I have a Table with User Entries and i need a value like UserID from one or more selected rows.
My first Column used this JS Code

        select: true,
        paging: true,
        processing: true,
        serverSide: false,
        pagingType: "full_numbers",
        ajax: "manage_user_ajax.php?pkSystem=" + pkSystem + "&a=" + action,
        columns: [
            {
                data: null,
                defaultContent: '',
                className: 'select-checkbox',
                orderable: false
            },
            {data: "lastname"},
            {data: "firstname"},

I use own buttons for submit my form on this Table.
But how did i become a value?

Datatable with checkbox, how to get IDs ?

Ultimate Datetime-Moment plugin not working!!!

$
0
0

Hi,
I can't get the ultimate plugin (https://datatables.net/blog/2014-12-18) work for my site.
I have datetime column.The input for the column (eisodos) from JSON is 'dd/MM/yyyy HH:mm:ss' e.g. 31/10/2018 10:03:00
The field in SQL Server is Datetime.In query.php ,i FORMAT it to 'dd/MM/yyyy HH:mm:ss' and encode to JSON.

If i FORMAT it to 'yyyy/MM/dd HH:mm:ss' it sorts fine in the Datatable,but i want 'dd/MM/yyyy HH:mm:ss' .

I include both scripts (latest versions) :

                  <script src="bower_components/moment/min/moment.min.js"></script>

and

                  <script src="bower_components/moment/min/datetime-moment.js"></script>

I have checked everything.

The result i get when i sort is:

I have been searching two days and i can't find a solution.
Can you help me?

Here is my code:

   $(function () {
   $.fn.dataTable.moment( 'dd/MM/yyyy HH:mm:ss' );

   var table = $('#example').DataTable({

   ajax : { url: "query.php",  dataType: "json", dataSrc: '' },
   "columns": [
         { "data": "eisodos" },
        // I have also tried the following (column render) but nothing changed.
        // "render": function(data, type, full) {return moment(data).format('dd/MM/yyyy HH:mm:ss'); }   
               ] ,
     "language": { "url": "Greek.json" }

      });
      });

Is there an ability to keep the scroll position after Editing in the pop up modal?

$
0
0

I have implemented DataTables Editor and integrated it with the Select extension. If a user selects a row at the bottom of a result set, clicks the edit button, and submits the changes, DataTables reloads the data and returns the scrolling back to the top. I was able to use Scroller for inline editing to keep scroll position but not with the Edit modal. Is there a way to keep position of the scroll after editing in the pop up modal?


Breakpoints and responsiveness

$
0
0

Hi there,
I want to always show the first column. In case the width exceeds the mobile breakpoint I want show all other columns. The last column should have higher priority.
I thought, that I can accomplish this with columns.classname = all, min-tablet etc.
It correctly shows only the "all" column in mobile, but shows all others in tablet view. The responsiveness breaks. Columns no longer are hidden, when they do not fit.
Is there any way to keep the responsiveness?
The min-tablet class forces columns to be visible, even if they don't fit.

Here is a codepen:
https://codepen.io/wiwo/pen/vVoPpX

Dropdown to display one field and update another

$
0
0

I have a dropdown that is populated depending on a part number:

            editor.dependent( 'salstkmaster.partnum', function ( val, data, callback ) {
                 
                $.ajax( {
                    url: 'datatables.php',
                    data: { action: "supplier", value: val },
                    type: 'POST',
                    dataType: 'json',
                    success: function ( json ) {
                        callback( json );
                    }
                });
            });

This uses the salstkitem.supplier field, and lets imagine it produces the following:

<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>

How can I get this field to update the enqitem.itemid field? Rather than salstkitem.supplier?

I have tried adding the following to my DataTable:

{ data: "salstkitem.supplier", editField: "enqitem.itemid" }

But this stops the dropdown from working. Any ideas?
If more information is required I can provide it, I just tried to cut stuff out for brevity.

Row object undefined after re-initializing dynamically generated data table with new parameter.

$
0
0

I have a data table that displays report info for a selected team. This table is generated when the user selects a team name from a drop-down. When the user clicks on a row in the generated table, a modal appears and is populated with data from the selected row.

Everything works as expected until the user selects a different team from the drop-down without refreshing the page. The data in the table displayed is exactly what is expected. HOWEVER, when the user clicks on a row to trigger the modal, the row object is undefined.

JS:

$(document).ready(function() {

            document.getElementById('teamsButton').innerHTML = 'Select Team  ' + '<span class="caret"></span>';
        });

        $('#teamsDropdown').on('click','.teamSelection', function() {
           
            var teamName = $(this).text();
            console.log("teamName selected from dropdown:", teamName);

                document.getElementById('teamsButton').innerHTML = teamName + '  ' + '<span class="caret"></span>';

            $("#teamReportsTable").DataTable({
                    destroy: true,

                    "ajax": {
                        "url": "/TeamReports/GetTeamReports?id=" + teamName,
                        "type": "GET",
                        "contentType": "application/json; charset=utf-8",
                        "datatype": "json"
                    },
                    "columns": [
                        {
                            "order": "",
                            "title": " ",
                            "data": "Path",
                            "orderable": false,
                            "render": function(type, data) {
                                return '<a target="_blank"  id="teamReportLink"><i class="fa fa-eye" id="viewReportIcon"></i></a>';
                            }
                        },
                        {
                            "title": "Category",
                            "data": "Folder"
                        },
                        {
                            "title": "Report Name",
                            "data": "Name"
                        },
                        {
                            "title": "Description",
                            "data": "Description",
                            "render": function(data, type) {
                                return type === 'display' && data.length > 80? '<span title="' + data + '">' + data.substr(0, 38) + '...</span>': data;
                            }
                        }
                    ],

                    aaSorting: [[1, 'asc']],

                    initComplete: function() {
                        //FILTER TABLE BY CATEGORY:
                        this.api().column(1).every(function() {
                            var column = this;
                            var select = $('<select><option value="">All Categories<option></select>').appendTo($(column.header()).empty()).on('change',function() {
                                var val = $.fn.dataTable.util.escapeRegex($(this).val());
                                column.search(val ? '^' + val + '$' : '', true, false).draw();
                            });
                            column.data().unique().sort().each(function(d, j) {
                                select.append('<option value="' + d + '">' + d + '</option>');
                            });
                        });


                        //REPORT ROW CLICK EVENT:
                        var table = $('#teamReportsTable ').DataTable();
                        $('#teamReportsTable tbody').on('click','tr',function(e) {

                            var rowData = table.row(this).data();

                            console.log("rowData", rowData);

                            if (e.target.id === "viewReportIcon") {
                                document.getElementById('teamReportLink').href = rowData.Path = rowData.Path.replace("//", "/").replace(":/", "://");
                            } else {
                                //REPORT DETAIL MODAL FUNCTIONALITY:
                                var teamReportCreationDate = moment(rowData.teamReportCreationDate).format("MMMM Do YYYY");

                                document.getElementById('teamReportName').innerHTML = rowData.Name;
                                document.getElementById('teamModalCategory').innerHTML = 'Category: ' + rowData.Folder;
                                document.getElementById('teamModalteamReportCreationDate').innerHTML = 'Created: ' + teamReportCreationDate;
                                document.getElementById('teamModalPath').href = rowData.Path = rowData.Path.replace("//", "/").replace(":/", "://");

                                if (rowData.Description === "") {
                                    document.getElementById('teamModalDescription').innerHTML = 'A description has not yet been provided for this report.';
                                } else {
                                    document.getElementById('teamModalDescription').innerHTML = rowData.Description;
                                }

                                if (rowData.ModifiedDate !== null) {
                                    var modifiedDate = moment(rowData.ModifiedDate).format("MMMM Do YYYY");
                                    document.getElementById('teamModalModifiedDate').innerHTML = 'Last Modified: ' + modifiedDate;
                                };
                                    $('#teamteamReportDetailModal').modal('show');
                            };
                            
                        });

                    }

                });
            });

Create cells with custom HTML rendering

$
0
0

I want to create cells with custom HTML rendering such as icons and clickable links. Is that possible without the underlying engine escaping my markup? I will have complete control over the markup so there is no security risk.

Changing simple join example to use local table editing causes errors

$
0
0

Hi,
I am trying to utilise Local Table Editing on the Editor example for a simple join.

I excluded the ajax option as per the example code but when I try to edit the Location field which is the joined field, the DataTable table does not display the new value. The Editor screen however does show the new value.

If I add a new row, a message appears saying "DataTables warning: table id=example - Requested unknown parameter 'sites.name' for row 37, column 3. For more information about this error, please see http://datatables.net/tn/4"

Please could you point me in the right direction?

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
//      ajax: "/api/join",
        table: "#example",
        fields: [ {
                label: "First name:",
                name: "users.first_name"
            }, {
                label: "Last name:",
                name: "users.last_name"
            }, {
                label: "Phone #:",
                name: "users.phone"
            }, {
                label: "Site:",
                name: "users.site",
                type: "select",
                placeholder: "Select a location"
            }
        ]
    } );

    $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url: "/api/join",
            type: 'POST'
        },
        columns: [
            { data: "users.first_name" },
            { data: "users.last_name" },
            { data: "users.phone" },
            { data: "sites.name" }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );
Viewing all 79589 articles
Browse latest View live




Latest Images