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

Adding ajax to child rows

$
0
0

Hi,

Hopefully very simple problem. In my old intranet system (8 years ago) that I have set up, there was a way of initiating nested tables for each table row. I had this setup to pull in an ajax request to load up a multi-row table of live data based on sending through a single unique value for each row. I have now updated everything including all of the datatables scripts while building an up-to-date intranet and i can no longer see how this work.

I have tried the 'Child Rows' script but struggling to get a value passed in and to get an ajax script loaded on click, and I've also tried a subtable option that I found but again can't get this to recognise the unique value passed in.

Does anyone have a setup that they could show me so that I can get this up and running again, please?

Appreciate all your help

Paul


Editor select field options filtering/disabling

$
0
0

For a dropdown select field in Editor I am using an ajax call to get user ids as select options - works great, however if one user id is selected and saved I want it not to appear in the select when I edit/add another item in Editor.
However, if I remove the option from the select, I am having trouble with already existing items that have saved user ids in their data.
How can I make sure, the data is only saved once per item and is not available to be chosen? So it's a unique selection and a user id is only connected to one item.

This is my ajax call to get the select field options set up:

$.ajax({
    url: datatablesajax.url,
    data: {
        action: 'getusers',
    },
    dataType: "json",
    success: function(data){
        var option = {};
        $.each(data, function(i, e){
            option.label = e.label;
            option.value = e.value;
            userselect.push(option);
            option = {};
        });
    }
}).done(function(data){
    contacteditor.field('user_id').update(userselect);
});

Specify column for global validator messages

$
0
0

Hi,
DT and Editor working fine with inline editing (whole row editing, blur submit, allIfChanged, server-side processing).
I use a global validator (server-side, .NET).

How can I control, in which column the global validator message appears?
Now it is shown "somewhere": in the right most (editor) column, which is far away from the correct place.

The messages of the field validators appear in their specific column.

Thanks for your help.

any one help me? for how to change table color or customize

$
0
0



Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Also I am Include plugins please see screenshot:

Does SearchPanes honor the placement of the 'P' in dom?

$
0
0

Link to test case: Unable to provide link, pretty dependent on backend
Debugger code (debug.datatables.net): Ok that tool is awesome, ran it and am unable to upload for some reason, versions are up to date, no common issues found
Error messages shown: None
Description of problem:
I have a big table with lots of options and it works amazingly well! Kudos and thank you for all the work. I use SearchPanes and some users of smaller laptops have complained that the search panes force the data off screen, I told them to scroll down but they insist it would be nicer if it could be hidden.

So I thought no big deal, I'll use the dom option to wrap the P in some type of collapsible element, so I modify the dom property and it doesn't appear to honor the P placement. I've moved the P to first position, to last position and searchpanes doesn't change.

I even tried the searchpanes sample on the doc page
dom: '<"dtsp-verticalContainer"<"dtsp-verticalPanes"P><"dtsp-dataTable"frtip>>'

And that only wraps the datatable elements, the searchpane elements are still outside.

Hierarchy looks like:

My Included Libraries are:
* DataTables 1.13.3
* Buttons 2.3.5
* Column visibility 2.3.5
* Responsive 2.4.0
* SearchPanes 2.1.1
* Select 1.6.1
* StateRestore 1.2.1
* Bootstrap 5 Formatting

DataTable config is: https://gist.github.com/timthedevguy/1a48451dbccf68d6e97663f64913323e
Sorry, forums kept removing formatting :(

I'm wondering if I'm just using an option that cancels another option or something. Thanks for any help you can give.

Editor updating incorrect line

$
0
0

Hello,
I am trying to let utility clients update route and sequence numbers in a table for meter readings. I am using inline editing. When the client selects a line, enters the updated information and tabs, Editor is not getting the correct index of the line. Therefore it is updating the wrong record. An example is they type a value in the search, but it always updates the first row in the datatable. This is especially bad when they use the search function since they have hundreds of records. Below is the code I am using to select the index and update the row. If anyone could help me I would appreciate it. I cannot provide a link to the page as it is a secure site and the datatable is populated via Ajax call to the database.

    editor = new $.fn.dataTable.Editor
                    ({
                        table: "#RouteSequenceOrderTable",
                        idSrc: "PIDN",
                        search: 'false',
                        fields:
                        [
                            {
                                label: "Route:",
                                name: "Route"
                            },
                            {
                                label: "Sequence:",
                                name: "Sequence"
                            }
                        ],
                    });

                    var cell;

                    // Activate an inline edit on click of a table cell
                    $('#RouteSequenceOrderTable').on('click', 'tbody td', function (e)
                    {
                        cell = this;

                        editor.inline(table.cell(this).index(), {
                            onBlur: 'submit'
                        });
                    });

 editor.on('preSubmit', function (e, data, action)
                    {
                        var index   = table.cell(cell).index().row;
                        var row = table.row(index, { order: 'index' }).data();
                        
                        // Create a deep copy of row
                        var newRow = JSON.parse(JSON.stringify(row));

                        // Get key
                        var keys = Object.keys(data.data);
                        var secondSetOfKeys = Object.keys(data.data[keys[0]]);

                        // Use key to set data in row object 
                        switch (secondSetOfKeys[0])
                        {
                            case "Route":
                                newRow.Route       = data.data[keys[0]].Route;
                                break;
                            case "Sequence":
                                newRow.Sequence    = data.data[keys[0]].Sequence;
                                break;
                            default:
                        }

 var table = $("#RouteSequenceOrderTable").DataTable
                    ({
                        data: data,
                        responsive: true,
                        destroy: true,
                        paging: false,
                        dom: 'Bfrtip',
                        "columnDefs":
                        [
                            { "orderData": [0, 1]},
                   
                        ],
                        "order": [[0, 'asc'], [1, 'asc']],
                        keys:
                        {
                            columns: [0,1],
                            keys: [9],
                            editor: editor,
                            editOnFocus: true

                        },
                        buttons:
                        [
                                {
                                    extend: 'excelHtml5',
                                    title: 'Route And Sequence'
                                },
                           
                        ],
                        columns:
                        [

                            { data: 'Route' },
                            { data: 'Sequence', type: "num"  },
                            { data: 'Address' },
                            { data: 'City' },
                            { data: 'State' },
                            { data: 'Zip' },
                            { data: 'PropertyStatus' },
                            { data: 'PIDN' },
                            { data: 'OwnerName' },
                            { data: 'Service' },
                            { data: 'Cycle' },
                            { data: 'SerialNumber' },
                            { data: 'ServiceStatus' }

                        ],

                    })

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

Change the server-side parameters sent.

$
0
0

First what a great tool Datatables is, thank you.

I have a HCL Domino server. The server natively supports json output, and supports pagination of the results. Unfortunately the parameters it requires are different to the parameters server-side sends. There is no way on the Domino side to change these parameters, is it possible through a config setting to change the parameters sent for server-side requests on the Domino Side?

Many thanks

Looking for a plugin that I thought I had seen

$
0
0

I thought I had seen a plugin or extension that would create a multi-select filter for columns and when an option was selected it would grey out and make not selectable options that are not a valid combination with the selected options

if not, is there a redraw function that would allow me to loop through existing options and mark invalid options as disabled?


Datatables does not retain the selected filter column values if the value has special characters.

$
0
0

I am using cascading datatables. It works fine. It appears, however, that if I select a value under Name or Office, the selected value is not retained in the dropdown menu. However, if I select Postion, it retains the selected value, for example: Director or System Architect. Columns 1 and 3 have special characters in the first and third column values, which probably explains why it does this. (. - :) etc. Is there a way around this? Users are unable to tell which value was selected from the dropdown menu.Thanks.

https://live.datatables.net/suwopemu/1/edit

datatables how to ignoring rows

$
0
0

I am initialising datatables on a table and everything works fine.
I have a drop down menu on my page with an onchange function. When the event is triggered, some rows get hidden with display style = none.

Is there any way i can have datatables ignore the hidden rows completely (page length and entries etc).

eg, if datatables initializes and finds 10 rows, after the onchange event, 3 might be hidden. I would like datatables to "update" by only show me 7 entries available etc.

myDT = $('#itemTable').DataTable();

$("#tselection").on("change", function (e) {
setVisibility();
myDT.draw(); //also tried invalidate does not work


});
function setVisibility() {
    
    var table, tr, i;
    table = document.getElementById("itemTable");
    tr = table.getElementsByClassName("itemRow");
    
    for (i = 0; i < tr.length; i++) {

           if (tr.classList.contains(showME) {
                tr[i].style.display = "";
           }
         
            
            else {
                tr[i].style.display = "none";
            }
        }
   }

Height of SearchPanes DIV

$
0
0

Is it possible to automatically set the height of SearchPanes to occupy only the necessary lines, in Bootstrap 3? Via CSS perhaps? The most I could do was set a fixed height.

editor generator db type not automatically populated

$
0
0

If my understanding is correct, the editor generator should populate the file settings.settings with the db type.

link to editor generator: https://editor.datatables.net/generator/

It is not doing this.

what is the database type for Microsoft SQL?

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="EditorGenerator.Properties" GeneratedClassName="Settings">
  <Profiles />
  <Settings>
    <Setting Name="DbType" Type="System.String" Scope="Application">
      <Value Profile="(Default)" />
    </Setting>
    <Setting Name="DbConnection" Type="System.String" Scope="Application">
      <Value Profile="(Default)" />
    </Setting>
  </Settings>
</SettingsFile>

I tried DbType "mssql" but that isnt correct.

Editor from Editor Generator not loading table from db

$
0
0

Well this is frustrating. Loading db tables into datatable.net is something I have been doing for several years.

Now that I am trying to learn how to use editor, I cant even get tables to load.

What could be wrong here?

I downloaded a fresh copy from https://editor.datatables.net/generator/

When i refresh the page, i get the following java error message telling me the data didnt make it.

Im getting inside of the controller verified by hitting a break point on line 16.

Here is my controller (stock from the Generator)

            /*
             * Controller for DB table Flex_OnCall
             * Created by http://editor.datatables.net/generator
             */
            using System;
            using System.Collections.Generic;
            using System.Net.Http.Formatting;
            using System.Web;
            using System.Web.Http;
            using DataTables;
            using EditorGenerator.Models;
            
            namespace EditorGenerator.Controllers
            {
                public class Flex_OnCallController : ApiController
                {
                    [Route("api/Flex_OnCall")]
                    [HttpGet]
                    [HttpPost]
                    public IHttpActionResult Flex_OnCall()
                    {
                        var request = HttpContext.Current.Request;
                        var settings = Properties.Settings.Default;
            
                        using (var db = new Database(settings.DbType, settings.DbConnection))
                        {


                            var response = new Editor(db, "Flex_OnCall", "TableID")
                                .Model<Flex_OnCallModel>()
                                .Field(new Field("day")
                                        .Validator(Validation.DateFormat(Format.DATE_ISO_850))
                                        .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_850))
                                        .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_850))
                                )
                                .Process(request)
                                .Data();

                            return Json(response);
                        }
                    }
                }
            }

Here is my SQL connection settings;

Here is a screenshot of SQL Studio showing the data table that was created by the Controller on the first run.

Issues with export to excel

$
0
0

I have a problem in exporting my table data to excel. There is a column in my table that contains string data with a structure similar to yyyy-mm-dd (some data like 1401-09-25). While exporting to excel, it is considered as date and in excel it is considered as date which is too large to be displayed.
Please guide me how to solve the issue.

Search parameters ignored when using StateSave

$
0
0

I have a datatable setup where I use the StateSave to display a child row, that works as expected but I want to also initially filter the data which looking at the docs I should use something like this

        search : {
                 search : 'bob'
        }

Which should load the table but be filtered by the word bob.

When I add the search to the datatable definition and load the page the search is being ignored and it loads the table unfiltered. If I remove the stateSave: true then the filtering works.

I would like to use the saveState and filtering together, am I doing something wrong?

My table setup is like this:

  var pendingTable = $('table.pending-claim-items').DataTable({
            bInfo: false,
            bLengthChange: false,
            autoWidth: false,
            stateSave: true,
            rowId: 'id',
            search : {
                search : '<?php echo $brokerName; ?>'
            },
            columnDefs: [
                {
                    targets: [2],
                    orderable: false
                }
            ],
            data: pendingItems,
            columns: [
                {
                    title: 'Category',
                    data: 'category',
                    width: "12%"
                },
                {
                    title: 'Sub Category',
                    data: 'subCategory',
                    width: "12%"
                },
                {
                    title: 'Date Entered',
                    data: 'dateEntered',
                    width: "10%",
                    className: 'text-center'
                },
                {
                    title: '',
                    data: 'status',
                    width: "7%"
                },
                {
                    title: 'Payment Type',
                    data: 'paymentType',
                    width: "16%"
                },
                {
                    title: 'Amount <span class="fs-7"> (%)</span>',
                    data: 'amountDue',
                    width: "12%",
                    className: 'text-end'
                },
                {
                    title: 'Reference',
                    data: 'reference',
                    width: "12%"
                },
                {
                    title: 'Comment',
                    data: 'commentButton',
                    width: "5%",
                    className: 'text-center'
                }
            ]
        });

Data table - Extra details child rows

$
0
0

Hi,

I m using data table 1.10.20 and using the column-controlled child rows by setting the below :

        dataTableOptions: {
            columns: [{
              title: "column 1",
              className: "col1",
              data: function (row){
                   ........
               }"},
             {
              title: "column 2",
              className: "col2",
              data: function (row){
                   ........
               }"},

             {
              title: "column 3",
              className: "col3 none",     //// hide from the header
              data: function (row){
                   ........
               }"},

             ..........
             ...........

           {
              title: "column 4",
              className: "col4 none",       ////// hide from the header
              data: function (row){
                   ........
               }"},

             {
              title: "column 5",
              className: "col5",      
              data: function (row){
                   ........
               }"},
        ],
       responsive: true,
        dom: 'ti'
    }

the functionality is working as expected. but when I maximize the window size or view on a smaller device, the other columns for example column 5 from the above code is also wrapped inside the child element. How can I make column 5 as a table header instead of showing it inside the child row?

https://datatables.net/ -- you the see the issue mentioned here in the example for the data table by zooming in on the screen.

however, it is not wrapped in this example https://www.datatables.net/blog/2017-03-31.

Am I missing something here?

Thanks

Select2 (Other?) on Editor Modal

$
0
0

I've been trying to get Select2 (is there a better alternative to DTE?) working with the editor, but it's been tricky. :D
Basically I wanted to use Select2 for when editing or adding a row in the table, in the editor's form/modal, in each input it suggests what the specific column of that input already has?

For example: in 'brands' column I already have some values like BMW, Mercarrari, Audi, Mercedes... When creating or editing a line, when I write "mer" it will already show the dropdon auto complete for "Mercedes" or "Mercarari".

The furthest I've come is not having console errors :D but the input disappears. Does anyone have a practical example of this scenario perhaps? It's easier to learn to try to understand the code. I couldn't find examples on the forum.

I have a test page if anyone needs to test. (I already sent it by private message to some users too, it's the same)

Trying to figure out the datasrc parameter

$
0
0

The HCL Domino server outputs this native JSON format. I am trying to figure out the datasrc parameters to populate a table with this data.

{
    "@timestamp": "20230304T172928,93Z",
    "@toplevelentries": "9",
    "viewentry": [
        {
            "@position": "1",
            "@unid": "C78DC6D4CA8C2D1E8525896200778001",
            "@noteid": "DFA",
            "@siblings": "9",
            "entrydata": [
                {
                    "@columnnumber": "0",
                    "@name": "LastName",
                    "text": {
                        "0": "Dill"
                    }
                },
                {
                    "@columnnumber": "1",
                    "@name": "FirstName",
                    "text": {
                        "0": "Tina"
                    }
                },
                {
                    "@columnnumber": "2",
                    "@name": "EMailAddress",
                    "text": {
                        "0": "TDill@fake.com"
                    }
                },
                {
                    "@columnnumber": "3",
                    "@name": "Country",
                    "text": {
                        "0": "UNITED STATES"
                    }
                }
            ]
        },
        {
            "@position": "2",
            "@unid": "A702AEA388F642CA8525896300521B41",
            "@noteid": "E0E",
            "@siblings": "9",
            "entrydata": [
                {
                    "@columnnumber": "0",
                    "@name": "LastName",
                    "text": {
                        "0": "Exchange"
                    }
                },
                {
                    "@columnnumber": "1",
                    "@name": "FirstName",
                    "text": {
                        "0": "Test"
                    }
                },
                {
                    "@columnnumber": "2",
                    "@name": "EMailAddress",
                    "text": {
                        "0": "TExchange@fake.com"
                    }
                },
                {
                    "@columnnumber": "3",
                    "@name": "Country",
                    "text": {
                        "0": "UNITED STATES"
                    }
                }
            ]
        }
    ]
}

This table would be:
Dill Tina TDill@fake.com UNITED STATES
Exchange Test TExchange@fake.com UNITED STATES

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

How to add a hidden column to display filter values in the dropdown?

$
0
0

I am using datatables from my project and it works great. However I am running into a problem with column filtering.

Position column has too long values. Using select.append( ''+d.substring(0,15)+'' ); doesn't work as I want the text to be different for each value.

Is there a way to use a hidden column with simple text to display for filtering so that I dont run into this?

So "System Architectghhghjjkjukjkj" for example would look Sys Architect in the column filter.

Link to my code - https://live.datatables.net/clone/7735/edit

Thanks.

DataTables + Bootstrap + Collapse in asp.net and problem not view co search, pagination, ordering...

$
0
0

Hello everyone, Thanks in advance for taking the time to help me.

I am using asp.net webform, bootstrap 4.0 as well as datatables.

I drag the data from sql behind in the code through vb.net, then I use StringBuilder() to send the thus generated datatable tree to html.

The DataTable works perfectly until I add a subtree / child! If I add a subtree / child, from that moment on I no longer see the search control, pagination... It depresses me a lot, I found that there is a problem but I don't know how to solve it.

    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <link href="Scripts/datatablestyle.css" rel="stylesheet" />

    <link href="lib/datatable/css/datatable4.min.css" rel="stylesheet" />
    <link href="lib/datatables/css/jquery.dataTables.min.css" rel="stylesheet" />

    <script src="Scripts/jquery-3.6.3.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
    <script src="Scripts/popper.min.js"></script>

    <script src="lib/datatables/js/dataTables.bootstrap.min.js"></script>
    <script src="lib/datatables/js/jquery.dataTables.min.js"></script>

    <div class="messagealert" id="alert_container"></div>

    <script>

        $(document).ready(function ($) {
            $('#myDataTable').DataTable({
                "scrollX": true,
                "ordering": true,
                "searching": true,
                "select": true,
            });
        });

    </script>

    <table id="myDataTable" style="width: 100%" class="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Barcode</th>
                <th>Order</th>
                <th>Lock</th>
                <th>Status</th>
                <th>Date/Time</th>
                <th>Patient</th>
                <th>Operater</th>
            </tr>
        </thead>
        <tbody>
            <tr data-toggle="collapse" data-target="#node1">
                <td>10006</td>
                <td>2100000100064</td>
                <td>22-RN-10006</td>
                <td>Lock</td>
                <td>Working</td>
                <td>15.11.2022 14:35:54</td>
                <td>Jame Irvas</td>
                <td>Anna Arcell</td>
            </tr>

     //start child

    <%-- <tr>
                <td colspan="10">
                    <div class="collapse" id="node1">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>IDs</th>
                                    <th>Barcode</th>
                                    <th>TU</th>
                                    <th>Name</th>
                                    <th>Qty</th>
                                    <th>Results</th>
                                    <th>Status</th>
                                    <th>Mi-132</th>
                                    <th>Go-178</th>
                                </tr>
                            </thead>
                            <tr>
                                <th>10006</th>
                                <th>10127</th>
                                <th>2110127000000</th>
                                <th>EK</th>
                                <th>CRP</th>
                                <th>mg/L</th>
                                <th>0</th>
                                <th>16.4</th>
                                <th>0</th>
                                <th>5</th>
                            </tr>
                        </table>
                    </div>
                </td>

             //end child
            </tr>--%>

        </tbody>
    </table>

after add child items

Viewing all 82314 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>