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

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?


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


How to fill out datatables with stored data json variable

$
0
0

I have one ajax query that store in variable 'msg' the data of one query in a table of database.

$.ajax({
    type: 'POST',
    dataType: 'html',
    url: page,
    data: {idtable: idtable},
    success: function (msg) {
        msg = $.parseJSON(msg);
    }
});

I need to fill out the table(using plugin DataTables) in front-end with data this variable, How to do this?

dataTable col fix problem on mobile devices

$
0
0

hi,

plz see this image (2 left col.)

how i can fix this ??

Thanks

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.

Insulation Anti-DC Micro Current Transformer Single Phase Coil

$
0
0

Quick Details: Quick Details◇Place of Origin: Zhejiang,Website:http://www.grt-relay.com, China (Mainland)◇Brand Name: WSD◇Model Number: WSD-704, WSD-704D◇Usage: Electronic◇Phase: Single◇Coil Structure: Toroidal◇Coil Number: AutotransformerPackaging

High Quality Flexible Miniature Single Phase Current Transformer

$
0
0

Quick Details:Quick Details◇Place of Origin: Zhejiang,Website:http://www.grt-relay.com, China (Mainland)◇Brand Name: WSD◇Model Number: WSD-706,WSD-706D◇Usage: Electronic◇Phase: Single◇Coil Structure: Toroidal◇Coil Number: AutotransformerPackaging

Customized Home Electric Relay Monophasic Relay Two-phase Relay And Three-phase Relay

$
0
0

Quick Details:◇Place of Origin:China◇Brand Name:GRT◇Model Number: GRT508B-90A ◇90A contact switching capability◇Only impulse excitation needed,Website:http://www.grt-relay.com, both for single and double coil. ◇Low power consumption, small in size◇Custom assemblies available with flexible wire and/or copper straps,and/or with integrated shunt◇4KV dielectric strength between coil and contacts◇RoHS compliant ◇IEC62055-31 UC2 compliant◇Outline dimensions: (38.5 x 30 x 17.5/16.5) mm Packaging

Metal Connectors For Plate Hold


5'' Purplish Colored Wheel Casters With Brake For Lean Pipe

4'' Purplish Colored Wheel Universal Casters For Lean Pipe

Three Wide Locker

2 Tier 2 Wide Locker

2 Tier 3 Wide Locker

Viewing all 81696 articles
Browse latest View live


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