vuetify 2.3+ table customSort for single column - vue.js

having issues to understand the documentation of vuetifys custom-sort in v-data-table
i don't get the customSorters?:
docs can be found here:
v-data-table
i try to use the custom-sort only when the column row is 'updated_at' or 'created_at'
because i have a German date time format when i display the result which comes from a SQL date time format
my column values where the customSort should be used looks like this:
the format is made with moment.js and is 'DD.MM.YYYY - HH:mm:ss'
i now need a way to compare these rows in a sort function simple with array.sort()
this is what i tried for now:
customSort(items, sortBy, sortDesc) {
console.log(sortBy)
if (sortBy.includes('updated_at')) {
items = items.map((e) => e.updated_at)
console.log(items)
items.sort((a, b) => a - b)
}
return items
}
this is not working at all

fixed this with help of this post:
here
instead of formatting the columns when getting them from the api, i use a v-slot and format them inside the table

Related

How to make ag-Grid table responsive such that headers and rows are transposed?

See the "Collapse Rows" animated example:
That's similar to what I want to achieve.
I'd like my table to be responsive using the approach of reorganizing itself such that it shows each original row transposed (but also transpose the headers and duplicate them so that they label each row).
ag-Grid seems like a phenomenal library that has countless features, so I was surprised that the docs seem not to specify how to accomplish my goal.
Unfortunately this feature is not available out of the box.
This is actually a feature request which can be found here:
https://www.ag-grid.com/ag-grid-pipeline/
AG-3142 Allow the grid to change columns for rows (transpose rows), so the grid show each row as one column, and each column as a row
To achieve this, you would have to write a function yourself to transpose the rows into one column.
You can then leverage Grid API methods to update the column and row data accordingly.
I've created a simple plunker which does this based on a button click:
function onBtnClick() {
let newColumnDefs = [{ field: 'transposed_rows' }];
let newRowData = [];
gridOptions.api.forEachNode((node) => {
let nodeDataValues = Object.values(node.data);
nodeDataValues.forEach((val) => newRowData.push({ transposed_rows: val }));
});
gridOptions.api.setColumnDefs(newColumnDefs);
gridOptions.api.setRowData(newRowData);
}

dynamic multiple grouptext in jqgrid

I have implemented multiple grouping in jqgrid which is dynamic(can be on 1 or many columns). And I want the grouptext to have a checkbox, column name and the value.
$("#Grid").jqGrid({
...
grouping:true,
groupingView:{
...
grouptext:['<input type="checkbox" class="groupHeader"/> ColumnName: {0}']
})
This will give me grouptext in only one groupheader. But I can have grouping on several columns where the columnName is dynamic. I tried this which is not working:
var columnNames=['ABC','DEF','GHI'];
var grouptext1=['<input type="checkbox" class="groupHeader"/> columnNames: {0}']
$('#Grid').jqGrid('setGridParam',{grouptext:grouptext1})
I can change the grouptext1 according to my needs. But I need a way to bind it to the jqGrid.
How can that be done?
Note that you have a typo errr in your code. The JavaScript is case sensitive and you have write grouping text property not correct. It should be groupText instead of grouptext as you write.
If you can see, the groupingGroupBy method has a second parameter - options. That is exactley what you need. This parameter is a grouping options. Having this you can set the groupText. in a case you want like this
$("#grid").jqGrid('groupingGroupBy',
['col1','col2'],
{
groupText : [ 'checkbox for col1', 'checkbox for col2']
...
}
);

How to format a column before running a where search in rails

I have a column with data type datetime. I want to search this column, using :where and return results based on a given day. The issue is, the :time_slot column has datetime objects, so I would need to format the column first, before running the search. Any suggestions on how I would this?
#movies = #movie_theater.showings.where({:time_slot => params[:day]})
Create a scope inside your model
scope :on_day, lambda { |day| where('extract(day from time_slot) = ?', day) }
which you can later use in your Controller #movie_theater.showings.on_day('2015-1-1')

Is getting the General ID same as getting FormattedID in rally?

I am trying to get the ID under "General" from a feature item in rally. This is my query:
body = { "find" => {"_ProjectHierarchy" => projectID, "_TypeHierarchy" => "PortfolioItem/Feature"
},
"fields" => ["FormattedID","Name","State","Release","_ItemHierarchy","_TypeHierarchy","Tags"],
"hydrate" => ["_ItemHierarchy","_TypeHierarchy","Tags"],
"fetch"=>true
}
I am not able to get any value for FormattedID, I tried using "_UnformattedID" but it pulls up an entirely different value than the FormattedID. Any help would be appreciated.
LBAPI does not have FormattedID field. You are correct using _UnformattedID. It is the FormattedID without the prefix. For example, this query:
https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1111/artifact/snapshot/query.js?find={"_ProjectHierarchy":2222,"_TypeHierarchy":"PortfolioItem/Feature","State":"Developing",_ValidFrom: {$gte: "2013-06-01TZ",$lt: "2013-09-01TZ"}},sort:{_ValidFrom:-1}}&fields=["_UnformattedID","Name","State"]&hydrate=["State"]&compress=true&pagesize:200
shows _UnformattedID that correspond to FormattedID as this screenshot shows:
I noticed your are using fields and fetch . Per LBAPI's documentation, it uses fields rather than fetch. If you want to get all fields, use fields=true
As far as the missing custom fields, make sure that the custom field value was set within the dates of the query.
Compare these almost identical queries: the first query does not return a custom field, the second query does.
Query #1:
https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1111/artifact/snapshot/query.js?find={"_ProjectHierarchy":2222,"_TypeHierarchy":"PortfolioItem/Feature","State":"Developing",_ValidFrom: {$gte: "2013-06-01TZ",$lt: "2013-09-01TZ"}}}&fields=["_UnformattedID","Name","State","c_PiCustomField"]&hydrate=["State","c_PiCustomField"]
Query #2:
https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/11111/artifact/snapshot/query.js?find={"_ProjectHierarchy":2222,"_TypeHierarchy":"PortfolioItem/Feature","State":"Developing",__At: "current"}&fields=["_UnformattedID","Name","State","c_PiCustomField"]&hydrate=["State","c_PiCustomField"]
The first query uses time period: _ValidFrom: {$gte: "2013-06-01TZ",$lt: "2013-09-01TZ"}
The second query uses __At: "current"
Let's say I just create a new custom field on PortfolioItem. It is not possible to create a custom field on PorfolioItem/Feature, so the field is created on PI, but both queries still use "_TypeHierarchy":"PortfolioItem/Feature".
After I created this custom field, called PiCustomField, I set a value of that field for a specific Feature, F4.
The first query does not have a single snapshot that includes that field because that field did not exist in the time period we lookback. We can't change the past.
The second query returns this field for F4. It does not return it for other Features because all other Features do not have this field set.
Here is the screenshot:

Rails 3 jquery date picker date not saving to database

When I submit my form I can see the date being sent to in the post. However, It doesn't save the date. If I do a date check it says it is not in the proper format. Here is my date picker function, it displays fine:
$j(function(){
$j("#mile_date").datepicker();
});
the $j is because I am using prototype as well so all jquery calls are using the the noconflict variable.
Here is the post:
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"Fj4HW/B4EOan/vcPZLJ75TvWkRH4ZKSFsPLlQLSD0cI=", "mile"=>{"odometer"=>"", "trip"=>"428.2
", "gallons"=>"24.959", "note"=>"", "temperature"=>"", "date"=>"06/22/2011"}, "commit"=>"Create Mile"}
So it sends the date fine but rails doesn't seem to like the format. It inserts a null value into the database. If I submit it with the default datefield with the drop downs it sends this and saves fine:
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"Fj4HW/B4EOan/vcPZLJ75TvWkRH4ZKSFsPLlQLSD0cI=", "mile"=>{"odometer"=>"", "trip"=>"428.2
", "gallons"=>"24.959", "mpg"=>"17.156136063144", "note"=>"", "temperature"=>"", "date(1i)"=>"2011", "date(2i)"=>"6", "date(3i)"=>"22"}, "c
ommit"=>"Create Mile"}
In the insert statement it inserts the date as:'2011-06-22'
Does Rails expect the date in 3 variables to construct the date format correctly? How can I get the datepicker to send the correct date format?
Thank you in advance,
I ran into the same issue. One solution is to simply change the format that the datepicker uses:
// in your javascript...
$j(function(){
$j("#mile_date").datepicker({
dateFormat: "yy-mm-dd"
});
});
Rails seems to be able to handle the yy-mm-dd format - I'm using that and am having no issues saving the date to the database. The only issue here is that some might find the yy-mm-dd format a little less good looking than mm/dd/yyyy...
As noted by #BaronVonBraun above rails doesn't seem to handle that format. Changing it as he suggested worked. However, for those wanting a different format than yy-mm-dd you can use the following. The user sees the format you want while rails gets the format it needs.
$j(function(){
$j("#show_date").datepicker({altField: '#mile_date', altFormat: 'yy-mm-dd'});
});
The show_date is the id of the field they see and the mile_date is a hidden field with the date rails needs.
Here is the documentation.
If anyone is using the jquery_datepicker gem , you'll want to use something similar to the following code in your rails view.
<%= form.hidden_field(:ship_date, :id => "ship_date") %>
<%= datepicker_input(:show_date, item.id, :size => 10, altField: "#ship_date", altFormat: 'yy-mm-dd', :value => item.ship_date.strftime("%m/%d/%Y"))%>
You can also use form.datepicker_input to attach the the date picker directly to the form, but in my use case, I wanted the date picker to reflect the localized date, which Rails would not accept. So I added a hidden form element and set the alternate field to it, works perfectly!
Or try the delocalize gem: https://github.com/clemens/delocalize
j('.jquery-calendar').datepicker().each(function(){
// convert dates from db to US format
var $input = j(this)
var found = $input.val().match(/^(\d{4})-(\d{2})-(\d{2})$/);
if(found){
$input.val(found[2]+'/'+found[3]+'/'+found[1]);
}
});
Kinda of hacky but made a helper the set things straight when I know I am giving the server dates in the mm-dd-yy format
def convert_to_y_m_d(date)
new_date = date.split("-")[2] + "-" + date.split("-")[0] + "-" + date.split("-")[1]
new_date
end