How to get all data of column in datatables when using ajax - ajax

Im currently using datatables with ajax integration. How can I get all the column's data for all the records? My problem is it only gives the current set of data from the table and not all the data. Please see my code below.
initComplete: function() {
var customer = table
.columns(2)
.data()
.eq(0) // Reduce the 2D array into a 1D array of data
.sort() // Sort data alphabetically
.unique() // Reduce to unique values
.toArray();
$.each(customer, function(key, value) {
$('#customer')
.append($("<option></option>")
.attr("value", value)
.text(value);
});
}

Related

laravel im getting value in view table before 4day how to keep once get value show in table if date after any time

Using this code I'm able to get data before 4days in view table, I want to display once I get data it present show any time in view table
$dueDate = Carbon::now()->addDays(4);
Payment::select( 'next_due_date')->whereDate('next_due_date', $dueDate)->get();
If you want to save the state you have many options.
Most convenient and fast ways are to save them in either cache or database itself.
Solution 1: saving in cache: (Receomented if you won't have too many rows in payments table)
$payments = Payment::select( 'next_due_date')
->where(function($q){
// Get rows that are current next_due_date or is cached
$q->whereDate('next_due_date', Carbon::now()->addDays(4))
->when(cache()->has('saved_payment_ids'), function(){
$q->orWhereIn('id', cache()->get('saved_payment_ids') ?? []);
});
})
->get();
// Remember forever current rows in cache
cache()->forever('saved_payment_ids', $payments->pluck('id')->toArray());
Solution 2: saving in db (Receomented way)
/**
* First you have to add boolean (tinyint) row in payments table
* Lets call it: payment_due_date
*/
$payments = Payment::select( 'next_due_date')
->where(function($q){
$q->whereDate('next_due_date', Carbon::now()->addDays(4))
->orWhere('payment_due_date', 1);
})
->get();
// Update new rows to save for future fetching
Payment::query()
->where('payment_due_date', 0)
->whereDate('next_due_date', Carbon::now()->addDays(4))->update(['payment_due_date' => 1]);

Can the index/key field of a Webix Datatable be something other than 'id'?

I have data parsed into a Webix Datatable that includes a property named 'id' for each object in that data. The 'id' is an integer but is not necessarily unique; not until all of the data in the datatable is validated. Each object also has a Unique Identifier where the property is named 'uid'. This is a short string and is unique to each object all of the time. Is there a way that the Webix Datatable can be directed to use the 'uid' property (corresponding to the 'uid' field in the Datatable) as the index/key for each object in the data table?
I've considered mapping the 'uid' property to 'id' and the 'id' property to something like 'objectId':
scheme:{
$init:function(obj){
obj.objectId = obj.id;
obj.id = obj.uid;
}
}
This seems pretty clunky when all I want to do is have the 'uid' property (as opposed to the 'id' property') as the index/key for each object in the Webix Datatable. Is there a better/direct way of doing what I'm trying to do?
Your idea of remapping the id in the scheme would be the most straightforward and standard way.
You could also create a data driver and specify that as the datatype. That is good for overarching data transformations of every data load. The driver has access to the raw ajax data before the component begins parsing the data.
webix.DataDriver.customParser = webix.extend({
getRecords: function (result) {
let data = result.data;
for(let i = 0; i < data.length; i++) {
data[i].oldId = data[i].id;
data[i].id = data[i].uid;
}
}
}, webix.DataDriver.json);
Then, in your view:
{
view: 'datatable',
url: someUrl,
datatype: 'customParser'
}

Why my Model Order_by ... Doesn't Work (data not sorted) (CODEIGNITER)

Im trying to show my data from Database in Order by DESC but it doesn't work, it's not sort my data.. (nothing change).. What wrong with my code ??? please HELPME solve this.
this my model Tiket_model.php
public function get_tiket() // semua tiket RELATION Begin here
{
$this->db->select('*');
$this->db->from('tiket');
$this->db->join('customer', 'customer.id_customer = tiket.id_customer');
$this->db->join('kursi', 'kursi.id_kursi = tiket.id_kursi');
$this->db->join('bus', 'bus.id_bus = kursi.id_bus');
$this->db->join('rute', 'rute.id_rute = kursi.id_rute');
$this->db->order_by("tiket.id_tiket", 'DESC');
return $query = $this->db->get()->result();
}
Additional information:
I'm Using Javascript Plugins DataTables to View my Data
SOLVED
Data not sorting because, Plugin Javascript DataTables automatically sorted my data.
This is way to fix my problem:
<script>
$(function () {
$("#tabel").DataTable({
"order": [[4, 'desc']] //which 4 is array of column you need to reference for sorting.
})
});
</script>
I'm using code above, DataTables options for sorting my data instead Codeigniter Query Builder.
For more Information DataTables ordering (sorting)

Defining Multiple Comparators for Sorting and Reverse Sorting Appcelerator Backbone Models

I am defining an Appcelerator DataGrid in the new Alloy implementation, which relies on the Backbone framework. I have successfully implemented a horizontally and vertically scrolling DataGrid, which also databinds data collections to the DataGrid via REST queries, and allows the user to sort the grid when touching column headers.
The one issue I have encountered is this. When implementing the data model using the Backbone model implementation, and I use the comparator to sort the data model in an ascending fashion. I have also extended the model to allow the user to define the sort criteria (passing a column definition for the filter).
Here is the question. I know when the grid is sorted in ascending order. Is it possible in a Backbone model to define a second comparator which will then sort in reverse order so if the user resorts I can sort in descending order (essentially creating two comparators)? I have seen questions about reverse sorting, but nothing about allowing two comparator options in one model.
A generic model I am following for Appcelerator is their example:
exports.definition = {
config : {
// table schema and adapter information
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// Extend, override or implement the Backbone.Model methods
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// Implement the comparator method.
comparator : function(book) {
return book.get('title');
}
}); // end extend
return Collection;
}
}
with the above in mind then, I would just like the second access to the comparator to essentially reverse sort the titles, if possible.
Thanks for any guidance.
Chris.
To sort in descending order for strings(case insensitive) or just numbers, try this:
var sort_descending = false; /* assuming you are able to set this variable when you need to sort */
var sort_attribute_name = "title"; /* assuming you can set the attribute name on which you want to sort */
book_list.comparator = function(book){ /* book_list is an instance of book_collection */
if(sort_descending){
if(isNaN(book.get(sort_attribute_name)){
var str = book.get(sort_attribute_name);
str = str.toLowerCase();
str = str.split("");
str = _.map(str, function(letter){
return String.fromCharCode(-(letter.charCodeAt(0))); /* from an SO answer*/
});
}
return -book.get(sort_attribute_name);
}
return book.get(sort_attribute_name);
};

How to use the array of values in the WHERE clause of my query

I am using asp.net mvc3. I want to pass an array from view to the controller using parameterMap as shown below. In my view:
parameterMap:
function (data, options) {
if (options === "read") {
sessionStorage.setItem("value","array");
val = sessionStorage.getItem("value"); // contains array
return { model: JSON.stringify(val) }; //passing array to controller
}
}
In controller:
public ActionResult SearchDetails( string model)
{
var query = (from ......).where();//want to compare array values in controller
}
but I am not able to retrieve those values in the controller. How can I retrieve these array of values in my controller without using looping statements?
My array contains only integer values (ids), while debugging the when I put cursor at the parameter of action method the values are coming in ""[{\"id\":1},{\"id\":2}]"" format. How can I use this array of values in my WHERE clause of my query?
if you are bound and determined to stick with the string input, I would think a call to Split would work. However, it would be much easier if you changed from bringing it in as a string to just bringing in the model. Have you tried something like:
public ActionResult SearchDetails( model model)
{
var query = (from ......).where();//want to compare array values in controller
}
are you trying to do something equivalent to a SQL IN? If that is the case then use .Contains in your query. For example:
public ActionResult SearchDetails(model model)
{
var query = from d in context.data
where model.Contains(d.id)
select d;
}

Resources