yadcf interface change to exFilterColumn confusion - yadcf

I am upgrading the yadcf version on my site from 0.6.9 to 0.8.8. (I'm also upgrading from datatables 1.9.4 to 1.10.10)
See the 0.6.9 version at my production site and the 0.8.8 version at my sandbox site
I have updated my calls to yadcf.exFilterColumn from two calls to a single call because now the defaults take an array of pairs.
But my filtered dataset is empty when the page loads, and I need to select a gender then click all for all the data to show up.
I'm sure it's something I'm not quite getting for the new interface.
Update: Simplified sandbox version here. See file TestStandings.js
Update 2: Daniel pointed out that "-1" for gender filter won't work. Apparently usegender = "-1" doesn't behave the same way in 0.8.8 as it did in 0.6.9 for some reason. I could try to figure out why it used to work, but that seems unproductive.
I added the following code after the exFilterColumn call (it's necessary for the gender to be filtered in some use cases)
// reset gender column if didn't mean to filter
if (usegender == "-1") {
yadcf.exResetFilters( _rrwebapp_table, [genderCol] )
}
but this gets exception at line 3624 of jquery.dataTable.yadcf.js because settingsDt.aanFeatures.f is undefined
Update 3: while debugging on the datatables side, I changed sDom from '<"H"Clpr>t' to the default 'lfrtip'. The exception mentioned above went away and the table loaded properly.

Here is how you should handle your scenario
Its wrong to ask for filtering for a -1 value because there is no such value in the table, so in order to reset a specific column just before calling exFilterColumn you should use the exResetFilters with noRedraw set to true (grab from 0.8.9.beta.31) you should call this function before your exFilterColumn
Old answer
I might have noticed multiple calls to the exFilterColumn for the same table, while in fact you should call it only once, just set the desired values for each column of the table,
See showcase page (first table)
And notice the relevant code below
yadcf.exFilterColumn(firstTable, [
[1, {
from: 1,
to: 40
}],
[3, "a_value"]
]);
If it still no goodm please provide the your table / yadcf init code and the code for calling the exFilterColumn
Update:
I noticed that your are using the following line of code
yadcf.exFilterColumn(_rrwebapp_table, [[divisionCol, usedivision], [genderCol, usegender]])
Where your usegender is set to "-1" which makes no sense, because its the value of the Select input reset option, so make sure you dont use "-1" as values in your exFilterColumn calls...

Related

Where do I enter moment.js code so a DataTables column appears in my chosen format?

I want to make data like 2022/12/15 (imported from Google Sheets at the moment of page load) display as "Dec 15" in one column, and as "Thu" in another column.
I found the format codes:
moment().format("MMM d"); // "Dec 15" and
moment().format("ddd"); // "Thu".
I read https://momentjs.com/docs/ and https://momentjs.com/guides/, but could not find:
Where do I enter that code?
Can I skip entering that code, and instead just enter this?:
$(document).ready(function () {
$('#example').DataTable({
columnDefs: [
{
targets: 4,
render: DataTable.render.datetime('MMM d'),
},
],
});
});
Perhaps I should separate my questions into different posted questions, but I imagine it will be more helpful for future readers to find the combined challenges asked and answered in a single thread.
I'm using the WordPress plugin "Inline Google Spreadsheet Viewer", which is built on DataTables.
[Edit: I realized I should not paste that code into inline_gdocs_viewer.php, and intended to paste it into igsv-datatables.js. I could not however figure out where to paste within that file. What should I look for to know where to insert it? (The author of that plugin publicly announced that no more support will be given.) Should I post the contents of the js file somewhere so you can see it?]
[Edit 2: Would entering that code make column 5 always displayed in MMM d format, even if I want column 5 to be displayed in a different format? Shouldn't specifying what format to apply to which column happen when I create a page / post and use the shortcode to embed the spreadsheet?]
(I read the plugin's documentation and I read DataTables documentation.)
If my table doesn't have a name, what do I use instead of #example? Do I need to name my table? If so, how? (I tried to find the answer at, for example, https://www.w3schools.com/html/html_tables.asp.)
The source for the longer code came from a live example where the dates were in column 5, but the code says "targets:4". To apply the code to column 3 (for example), should I enter targets:2? I read https://datatables.net/reference/option/columns.render, but bizarrely that didn't address this basic question.
If you're wondering if I upgraded DataTables from the old version that comes with Inline Google Spreadsheet Viewer, yes I did.
If you're wondering if I got the script array to call moment.js, I might have. Into the scripts array I added
,
'moment' => array(
'src' => plugins_url('moment.min.js', __FIL__),
'deps' => array( 'moment' )
)
I'm not sure about the "deps" part. Does it mean dependencies? Was I right to use "moment" twice in that code?
If you only know a possible answer to one of these questions, that's better than nothing, so please do share what you can.
I know the Moment team recommends you choose a different library than Moment for new projects, but DataTables to this day recommends Moment for sorting by Day of the week or sorting by Date.
Thanks
Using moment.js 2.29.2 and DataTables 1.13.1.
What I tried, and what I expected:
I read the documentation for all the programs, and I read forum discussions for all the programs, and I studied examples, expecting to find where to enter the code, but nowhere could I find what to do with it. It was always assumed that that part was already known.

SubmitForm then Patch results in "The data returned by the service was invalid"

I'm building a PowerApps app on Azure SQL
The requirement
I have a form which has "Save" and "Confirm" buttons.
Both buttons should save the form data. The Commit button should also set database column "Confirm" to 1
I've read at length about how I can programatically override the update value of a hidden control for this. But I'm not satisfied with the level of complexity (maintenance) required to get this working, i.e.
Populate a variable with the current db value
In the button code set the variable value
In the form field, set the update property to the variable
What I'm Trying
So I'm trying a different approach: SubmitForm then Patch. Even though this requires an extra database call, I'd like to understand if this will work. This is the code for OnSelect in the commit button:
// Save the record
SubmitForm(frmEdit);
// Update confirmed to 1
Patch('[dbo].[Comments]',cRecord,{Confirmed:1});
Some Complexities
Note that my record is a variable, cRecord. In short I want this app to be able to upsert based on URL parameters.
This is my App.OnStart which captures URL values, inserts a record if required. Regardless, the result of this event is that cRecord is set to the record to be edited.
// Cache employees and store lookups (as they are in a different db)
Concurrent(Collect(cEmployees, Filter('[dbo].[SalesPerson]', Status = "A")),Collect(cStores, '[dbo].[Store]'));
// Check for parameters in the URL. If found, set to Edit/Add mode
Set(bURLRecord,If((!IsBlank(Param("PersonId")) && !IsBlank(Param("Date"))),true,false));
// If URL Parameters were passed, create the record if it doesn't exist
If(bURLRecord,
Set(pPersonId,Value(Param("PersonId")));
Set(pDate,DateValue(Param("Date")));
// Try and find the record
Set(cRecord,LookUp('[dbo].[Comments]',SalesPersonId=pPersonId && TransactionDate = pDate));
If(IsBlank(cRecord),
// If the record doesn't exist, create it with Patch and capture the resulting record
Set(cRecord,Patch('[dbo].[Comments]',Defaults('[dbo].[Comments]'),{SalesPersonId:pPersonId,TransactionDate:pDate}))
);
// Navigate to the data entry screen. This screen uses cRecord as its item
Navigate(scrEdit);
)
frmEdit.Item is set to cRecord. As an aside I also have a gallery that sets this variable value when clicked so we can also navigate here from a gallery.
The navigating using new and existing URL parameters works. Navigating from the gallery works.
The problem
When I press the Commit button against a record which has Confirmed=0 I get this popup error:
The data returned by the service is invalid
When I run this code against a record which already has Confirmed=1 I don't get an error
If I run the PowerApps monitor it doesn't show any errors but it does show some counts being run after the update. I can paste it here if required.
I also tried wrapping the Path in a Set in case it's result was confusing the button event but it didn't make a difference.
What I want
So can anyone offer me any of the following info:
How can I get more info about "The data returned by the service is invalid"?
How can I get this to run without erroring?
Is there a simpler way to do the initial upsert? I was hoping a function called Patch could upsert in one call but it seems it can't
With regards to the setting field beforehand approach, I'm happy to try this again but I had some issues implementing it - understanding which control where to edit.
Any assistance appreciated.
Edit
As per recommendations in the answer, I moved the patch code into OnSuccess
If(Confirmed=1,Patch('[dbo].[CoachingComments]',cRecord,{Confirmed:1}));
But now I get the same error there. Worse I cleared out OnSucces and just put SubmitForm(frmEdit); into the OnSelect event and it is saving data but still saying
The data returned by the service was invalid
First things first,
Refactoring has multiple steps,
I can t type all out at once...
The submitform and patch issue:
Never use the submitforn with extra conplexity
Submitform is only the trigger to send the form out,
The form handler will work with your data...
If you hsven t filled out the form correctly, u don t want to trigger your patch action...
So:
On your form, you have an OnSucces property,
Place your patch code there...
Change your cRecord in your patch statement:
YourForm.LastSubmit

Iterating store in relay optimisticUpdater

Apologies in advance, I'm new to relay and not sure I've got all the terminology here right...
I have a (simplified) graph that looks like:
customer {
summary(id: "ABC123") {
records { // This is an array of Record
tag
}
}
}
Customer, Summary and Record are all objects with global IDs - they show up as records in the Relay DevTools inspector.
I have a mutation that removes a tag by name (from elsewhere in the graph - not shown), from which I need to update the customer summary object to remove the record with associated tag. I have tried two approaches and not gotten very far with either:
Re-request customer.summary as part of the mutation. The problem is I don't know what the ID is at that point. (Maybe I can thread it through some how, but that would be messy.) Also doesn't really solve the problem, since I'd like to do this optimistically.
In an optimistic updater, remove any tag record that matches. This seems like it should work, but the RecordProxy doesn't appear to have a rich enough API to enable me to do this.
First approach, I can't seem to get access to the summary record via the root:
const customer = store.getRoot().getLinkedRecord('customer') // works!
customer.getLinkedRecord("summary") // undefined
customer.getLinkedRecord("summary", {id: "ABC123"}) // undefined
Second approach, if I could ask the store for "all records of type" or even "all records" I could iterate through and find the one I need to edit, but this doesn't seem to be a method that's exposed (even though Relay DevTools must be doing it somehow).

Openrefine not working as expected

I'm very new to OpenRefine, so please bear with me if i have made a simple mistake.
I'm parsing a HTML website to gather some date.
Everything went fine with fetching the individual pages, but now the parsing of the HTML fails.
I'm creating a new column, based on the one holding all the page's HTML. I'm trying to get to the data in a specific DIV[20].
In the"create column based on this column" window it gives me a preview when using value.parseHtml().select("DIV")[20] , which results in exactly what i need... executing it gives me nothing but blank cells.
it even tells me that it is "filling 0 rows with grel:value.parseHtml().select("DIV")[20]"
Any clue what i'm doing wrong here?
You just need to finalize with .toString() to output the JSON.org object AS a string.
This is explained on our wiki here: https://github.com/OpenRefine/OpenRefine/wiki/StrippingHTML#extract-html-attributes-text-links-with-integrated-grel-commands
I also updated the select() function with that example: https://github.com/OpenRefine/OpenRefine/wiki/GREL-Other-Functions#selectelement-e-string-s

fnServerParams isn't working for me

I need to send custom filters to my server side processing for dataTables.net
I have a drop down which contains dates, after the user has seleted a date, then the tables need to reflect the option they have selected. I can't for the life of me work out why this isn't sending anything:
"fnServerParams": function (aoData) {
aoData.push({"name": "iArchiveYears", "value": $("ddYears option:selected").text()})
when I look in firebug, iArchiveYears in there, but empty.
Even hardcoding a value in here instead of the drop down value doesn't work.
Any advice most welcome.
Use $("#ddYears option:selected")
Instead of
$("ddYears option:selected").
# missing.