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

Adding custom message that is updated as user fills out a form

$
0
0

My data include admission date and discharge date allowing the calculation of LOS.

The LOS should be the max allowed for data entry of a third field. As the user enters admission and discharge date, I would like to update (without going back to the server) the message for the third field "Please enter a number between 1 and LOS."

It seems that this can be accomplished using the API method fields().message, but I am unable to get this to work. I tried to define the message as a function as in:
message: function(data,type,row){var test=data().pluck('ddate'); return test;}
but that just shows the text of the function as the message.

I also don't understand from the documentation how to get text editor to listen to an edit event on the admission and discharge date fields. I usually can work well from examples, but there are no examples that show the syntax for generating custom dynamic field messages, all I have found is at https://editor.datatables.net/reference/option/fields.message.

Thank you for kind feedback.


Submit on row blur when using inline editing?

$
0
0

Using inline editing, is there a way to submit on row blur instead of on the cell blur?

Toggle button not work on page 2 and so on. How can I fix it.

$
0
0


See the image of first page. The toggle button work on 1st page.

Toggle button not properly working on page 2.

DataTable date filter function not working on Chrome for mobile

$
0
0

Hello all,
i'm having a strange issue:
this function is working perfectly on desktop:

$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iFini = document.getElementById('date_min').value;
var iFfin = document.getElementById('date_max').value;
var iStartDateCol = 3;
var iEndDateCol = 3;
iFini=iFini.substring(0,4) + iFini.substring(5,7)+ iFini.substring(8,10);
iFfin=iFfin.substring(0,4) + iFfin.substring(5,7)+ iFfin.substring(8,10);

                var datofini=aData[iStartDateCol].substring(0,4) + aData[iStartDateCol].substring(5,7)+ aData[iStartDateCol].substring(8,10);
                var datoffin=aData[iEndDateCol].substring(0,4) + aData[iEndDateCol].substring(5,7)+ aData[iEndDateCol].substring(8,10);


                if ( iFini === "" && iFfin === "" )
                {
                    return true;
                }
                else if ( iFini <= datofini && iFfin === "")
                {
                    return true;
                }
                else if ( iFfin >= datoffin && iFini === "")
                {
                    return true;
                }
                else if (iFini <= datofini && iFfin >= datoffin)
                {
                    return true;
                }

                return false;
            }
        );

But for some reason when i try to filter the data table on Mobile (android 7 - latest chrome version) the filter is not working.

These are my includes:


<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap.min.js"></script>

Can you think of any reason why?

dataTable col fix problem on mobile devices

$
0
0

hi,

plz see this image (2 left col.)

how i can fix this ??

Thanks

Customized search applicable to both normal datatable and datatable with child rows.

$
0
0

I have an application with two datatables.

1.Has only parent rows (no child rows) say datatable1.
2.Has parent rows as well as child rows say datatable2.

I want to implement only one search for both the datatables.

For the datatable2 I implemented davidkonrad's answer on this link: https://stackoverflow.com/questions/30471089/datatables-search-child-row-content/ which works fine.
But the search does not work for the datatable2.

Any help would be greatly appreciated.

Thank you.

datatables editor and having to return custom JSON

$
0
0

Okay because of the specific way the actual table is populated using JSON. I have to duplicate the custom JSON when returning. Now to return this custom JSON Would I use echo or return?

dataTables editor plugin DateTime format issue

$
0
0

I'm using EF6 + MVC for a site. The dataTables editor is used for an UI. One table has a field 'StartDate'. It is a datetime type in the SQL Server.

It works fine until when I try to edit the 'StartDate' value. From the browser debug, I can see that the JSON send from backend to UI is in the timestamp format, i.e. /Date(1541923200000)/ .

In the dataTables, I convert this to the correct local datetime format, so it shows correctly.

However, I could not figure out how to do this in Editor. It always shows the /Date(1541923200000)/ .

The code I use is:

editorAdvertisement = new $.fn.dataTable.Editor({
    ajax: '/APN/GetAdvertisementData',

    table: "#tblAdvertisements",
    fields: [{
        label: "StartDate",
        name: "AdvStartDate"
        , type: "datetime"
        , format: 'MM\/DD\/YYYY h:mm a'
    }, {
        label: "Deadline",
        name: "AdvDeadline"
        , type: "datetime"
    }, {
        label: "TitleOfAdv",
        name: "TitleOfAdv"
    }, {
        label: "ListPrice",
        name: "ListPrice"
    }
    ]
});

var tbl = $('#tblAdvertisements').DataTable({
    pageLength: 10,
    dom: '<"html5buttons"B>lTfgitp',
    ajax: '/APN/GetAdvertisementData'
    ,
    columns: [
        {
            data: "AdvStartDate", name: "AdvStartDate"
            , type: "datetime"
                , render: function (value) {
                    var r = convertDate(value);
                    return r;
                }
            , "autoWidth": true
        },
        {
            data: "AdvDeadline", name: "AdvDeadline"
            , type: "datetime"
            , render: function (value) {
                var r = convertDate(value);
                return r;
            }
            , "autoWidth": true
        },
        { data: "TitleOfAdv", name: "TitleOfAdv", "autoWidth": true },
        {
            data: "ListPrice", name: "ListPrice", "autoWidth": true
            , render: $.fn.dataTable.render.number(',', '.', 0, '$')
        }
    ],
    order: [1, 'asc'],
    select: {
        style: 'os',
        selector: 'td:first-child'
    },
    buttons: [
        { extend: "create", editor: editorAdvertisement }
        , { extend: "edit", editor: editorAdvertisement }
        , { extend: "remove", editor: editorAdvertisement }

    ]
    , select: true
    , searching: false
    , paging: false

});

In the controller

[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult GetAdvertisementData()
{
    var request = HttpContext.Request.Form;
    var settings = Properties.Settings.Default;

    using (var db = new Database(settings.DbType, settings.DbConnection))
    {
        var response = new Editor(db, "Advertising", new[] { "AdvertisingID" })
            .TryCatch(false)
            .Model<Advertising2>()
            .Field(new Field("AdvStartDate")
                .Validator(Validation.DateFormat(
                    "MM/dd/yyyy",
                    new ValidationOpts { Message = "Please enter a date in the format MM/dd/yyyy" }
                ))
                .GetFormatter(Format.DateTime("yyyy-MM-dd HH:mm:ss", "MM/dd/yyyy"))
                .SetFormatter(Format.DateTime("MM/dd/yyyy", "yyyy-MM-dd HH:mm:ss"))
            )
            .Field(new Field("AdvDeadline")
                .Validator(Validation.DateFormat(
                    "MM/dd/yyyy",
                    new ValidationOpts { Message = "Please enter a date in the format MM/dd/yyyy" }
                ))
                .GetFormatter(Format.DateSqlToFormat("MM/dd/yyyy"))
                .SetFormatter(Format.DateFormatToSql("MM/dd/yyyy"))
            )

            .Field(new Field("TitleOfAdv"))
            .Field(new Field("ListPrice"))

            .Process(request)
            .Data();

        return Json(response, JsonRequestBehavior.AllowGet);
    }
}

How to fix this?


`row.add()` throws error when attempting to add a row using an object.

Problem with jQuery Datatables Buttons - Excel Export - Using Special Character like "&" or "

$
0
0

Hi,

like i mentioned in the header, we have a problem with the excel export funtion from jQuery Datatable Buttons - when using special characters like "&" or "<". The excel export function works great if the data in the Datatable doesnt contain any "&" or "<".

the csv export function has no problem with the special character its seems like this problem only happens in the export to excel function.

is there any solution for this problem?

best regards

[How-To] Install DataTables with Meteor JS + Bootstrap 3

$
0
0

Hi, I decided to write about the process how I successfully installed DataTables with MeteorJS.

In my case :

  • Meteor version 1.4.3.2 (as for March 2017)
  • Installed via npm
  • Bootstrap 3 - Note that, I'm not using the default styling

DataTables is a jQuery plugin, thus, there's a trick to bind the plugin with the existing jQuery that comes with Meteor. I'm using import as this example is in ES6.

Installation

Step 1 :

Install DataTable core via npm : npm install --save datatables.net

Step 2 :

Install DataTable Bootstrap via npm : npm install --save datatables.net-bs

Step 3 :

Import datatable core and datatable bootstrap into you file. For example, you can write like this :

import datatables from 'datatables.net';
import datatables_bs from 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';

The third line is where I import the css for datatable bootstrap.

Step 4 :

Bind the "plugin" with jQuery, within the .onCreated(...) block :

datatables(window, $);
datatables_bs(window, $);

If you're working inside the body template, then, the code will look something like this :

Template.body.onCreated(function(){
    datatables(window, $);
    datatables_bs(window, $);

    // rest of your code
});

Usage

Let's say this happen inside your body template (body tag).

HTML :

<body>
    <table id="mytable" class="table table-hover table-bordered">
        <thead>
            <tr>
                <th>Column Header 1</th>
                <th>Column Header 2</th>
                <th>Column Header 3</th>
                <th>Column Header 4</th>
            </tr>
        </thead>
    </table>
</body>

I recommend that we do the init inside .onRendered(...) block :

Template.body.onRendered(function(){
    var data = [
        ['Data 1', 'Data 2', 'Data 3', 'Data 4'],
        ['Data 1', 'Data 2', 'Data 3', 'Data 4']
    ];

    $('#mytable').DataTable({
        data : data
    });
});

That's all. It should be working now :wink:

Does editor work with nonstandard named id columns in database.

$
0
0

We're using a mix of virtuemart and custom tables none of which of a standard id field. Does the PHP editor instance posess the ability to use the customs like virtuemart_product_id and pid?

Left join the same right.table.id_field to TWO left.table.field_1 and left.table.field_2

$
0
0

I have two tables: teams, and players. (equpos and jugadores)
teams table structure: id, player_1_id, player_2_id (equipos.id_jugador_1 and equipos.id_jugador_2)
players table structure: id, name. (actually id, apellido, nombre, but that doesn't change things)
Each team has exactly two players. Players are selected from the players table. Each record in teams table has a unique team id, and has two different player ids, belonging to the players in that team.
I want to edit the teams table. player_1 should have a select drop down, populated from the players table. Edit field should be players.id, but the form should display players.name for the selected id. This is done with a left join. No problem. Now I want the second player to have his own select drop down list, populated from the very same table players, because both of them are players, and I store all of them on the same table.
I tried to add a second ->leftJoin() changing the condition. but against the same table.
I keep getting a PHP error:
"An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'players'"

Here's my code:

    Editor::inst($db, 'equipos')
    ->field(
    Field::inst('equipos.numero'),
    Field::inst('equipos.id_torneo')
    ->options(Options::inst()
    ->table('torneos')
    ->value('id')
    ->label('nombre')
    )
    ->validator('Validate::dbValues'),
    Field::inst('equipos.id_jugador_1')
    ->options(Options::inst()
    ->table('jugadores')
    ->value('id')
    ->label(['apellido', 'nombre'])
    ->render(function ($row){return $row['apellido'].', '.$row['nombre'];})
    ),
    Field::inst('equipos.id_jugador_2')
    ->options(Options::inst()
    ->table('jugadores')
    ->value('id')
    ->label(['apellido', 'nombre'])
    ->render(function ($row){return $row['apellido'].', '.$row['nombre'];})
    )
    )
    ->leftJoin('torneos', 'torneos.id', '=', 'equipos.id_torneo')
    ->leftJoin('jugadores', 'jugadores.id', '=', 'equipos.id_jugador_1')
    ->leftJoin('jugadores', 'jugadores.id', '=', 'equipos.id_jugador_2')
    ->process($_POST)
    ->json();

The code has Spanish names. jugador = player, team = equipo. Also, I put my question in the simplest terms I could find, so the code is slighthly more complex. I hope it'll be fine.
Thanks.

Datatable pagination does not appear properly

$
0
0

I followed the example found here: https://datatables.net/examples/styling/bootstrap.html
I tried it on Google Chrome, Mozilla Firefox and even Internet Explorer.
Also, I am using the same version of (Bootstrap, JQuery and Datatables). It works but, unfortunately, the pagination under the table does not appear properly (It looks like a sequence of page links rather than page buttons [See the attached figure])

Could you help me?

Error undefined length, start, draw, search

$
0
0

hi, i want to ask how to make server side datatables on codeigniter.

this my model php

[code]
class Manifest_in_m extends CI_Model{

var $table = "awb_incoming";
var $select_column = array("id", "no_awb", "air_line", "product");
var $order_column = array(null, "no_awb", "air_line", null, null);

function make_query()
{
   $this->db->select($this->select_column);
   $this->db->from($this->table);

   if(isset($_POST["search"]["value"]))
   {
        $this->db->like("no_awb", $_POST["search"]["value"]);
        $this->db->or_like("air_line", $_POST["search"]["value"]);
   }

   if(isset($_POST["order"]))
   {
        $this->db->order_by($this->order_column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
   }
   else
   {
        $this->db->order_by('id', 'DESC');
   }
}

function make_datatables(){
   $this->make_query();
   if($_POST["length"] != -1)
   {
        $this->db->limit($_POST['length'], $_POST['start']);
   }
   $query = $this->db->get();
   return $query->result();
}

function get_filtered_data(){
   $this->make_query();
   $query = $this->db->get();
   return $query->num_rows();
}

function get_all_data()
{
   $this->db->select("*");
   $this->db->from($this->table);
   return $this->db->count_all_results();
}

}
[/code]

this the controller

[code]
class Manifest extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('manifest_in_m');
}

public function index()
{
    $this->load->view('manifest_incoming');
}

function fetch_user(){
   $this->load->model("manifest_in_m");
   $fetch_data = $this->manifest_in_m->make_datatables();
   $data = array();
   foreach($fetch_data as $row)
   {
        $sub_array = array();
        $sub_array[] = $row->no_awb;
        $sub_array[] = $row->air_line;
        $sub_array[] = $row->product;
        $data[] = $sub_array;
   }
   $output = array(
        "draw" => intval($_POST["draw"]),
        "recordsTotal" => $this->manifest_in_m->get_all_data(),
        "recordsFiltered" => $this->manifest_in_m->get_filtered_data(),
        "data" => $data
   );
   echo json_encode($output);

}

}
[/code]

i didn't create the view because i want to check my json first, but my json result like this

Message: Undefined index: length
Filename: models/Manifest_in_m.php
Line Number: 33

Message: Undefined index: length
Filename: models/Manifest_in_m.php
Line Number: 35

Message: Undefined index: start
Filename: models/Manifest_in_m.php
Line Number: 35

Message: Undefined index: draw
Filename: controllers/Manifest.php
Line Number: 30

i don't know why, but this is happend only for me, please help me, thank you


Error occurs plz solve..

$
0
0

I'm trying to implement CRUD operation using datatableseditor using Backbone, RequireJS and Datatables.But I'm getting the error message:

$.fn.dataTable.Editor is not a constructor":
why it occurs..what is the reason???

Here is my code...
var editor;
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: "/View/GetList",
table: "#sellertable",
fields: [{
label: "SELLER CODE:",
name: "Sellercode"
}, {
label: "EMAIL:",
name: "Email"
}, {
label: "MOBILE:",
name: "Mobile"
}, {
label: "ISACTIVE:",
name: "Isactive"
}

            ]
        });

        $('#sellertable').DataTable({

            ajax: {
               url: "/View/GetList",
                type: "POST",
                datatype: "json"
            },
            serverSide: true,
            columns: [
                { data:"Sellercode"},
                { data: "Email"  },
               { data: "Mobile" },
                { data: "Isactive" }

            ],
            select: true,

            buttons: [
                { extend: "create", editor: editor },
                { extend: "edit", editor: editor },
                { extend: "remove", editor: editor }
            ]
        });
    });

Pagination incorrect with server-side

$
0
0

Hello,

Thank you for the great plugin.

I'am using DataTables to retrieve data from Asp.net web service.

The amount of rows in database is 128, the DataTables configuration is with pageLength to 40 and server processing is enabled.

When a first ajax sent to the service and get a response, we have a pagination with 5 pages which is wrong, we must have only 4 pages.

The web service send the correct value in recordsTotal (128) and recordsFiltered (128), the data is 40 objects.

Another point we have on bottom :
Showing 0 to 0 of 0 entries (filtered from NaN total entries)

I'am using the DataTables 1.10 version.

Reagrds Taha

Replace text for imagen

$
0
0

Hi, I'm using Datatable, in some columns I have a 1 or a 0, and I want to replace this 1 or 0 in an imagen..

It is possible?

With html table I know how to do it, but with DataTable not..

Thanks

fnIsOpen is not working

$
0
0

Here is my code
$('#tblsamplebody ').on('click', 'img', function () {
var nTr = $(this).parents('tr')[0];
var nTds = this;
if (dTable.fnIsOpen(nTr)) {
/* This row is already open - close it */
this.src = "http://i.imgur.com/SD7Dz.png";
dTable.fnClose(nTr);
}
}

Usind DT1.10.7
DT tabletools 2.2.4

DataTable : how to reload/update one row of dataTable? ajax.reload()

$
0
0

I am using MongoDb as my database , laravel for server and angularjs 1.6 for fronted.

How to reload one row of DataTable instead of loading whole content of the DataTable.

I tired like this

setInterval( function () {
data_table.ajax.reload( null, data_table.rows({selected:true}).data()[0]._id );}, 30000 );

I am passing one Id in second argument in ajax.reload API.

I am expecting that the above code will call Laravel show($id) (In controller) method , the updated value of that Id I will fetch from MongoDb return to DataTable so that DataTable will update only that particular row.

I am not sure that my above approach is correct or not, so please help me to figure out How to update one row in DataTable.

Viewing all 81693 articles
Browse latest View live