One DT, 2 editor forms
One DT, 2 editor forms
Hi
The 1st editor form uses the standard create, edit and remove extensions but form #2 gets called from a custom button. DT and editor form #1 share the same Ajax method. Form #2 has a different Ajax method that should not refresh the DT as the data it handles is different background data the user can edit but not see directly via the DT. He needs to click the custom button to view and edit that data. The forms handle data across 2 different tables who share the same foreign key.
var editor2 = ModifyCustomerSubPackSNsAssociations_editor();
(DT code)
buttons: [
{ extend: 'create', editor: editor1 },
{ extend: 'edit', editor: editor1 },
{ extend: 'remove', editor: editor1 },
{
text: '@(lblo.lblAssociatedSNs)',
extend: 'edit', editor: editor2
}
],
Code for ModifyCustomerSubPackSNsAssociations_editor:
function ModifyCustomerSubPackSNsAssociations_editor() {
var editor = new $.fn.dataTable.Editor({
destroy: true,
ajax: {
url: '/CustomerSubsPacks/CRUDCustomerSubsPacksSNs/',
data: function ( d ) {
return $.extend( {}, d, {
intContTpe: intContTpe1
} );
},
type: 'POST',
async: true,
cache: false
},
table: '#tblDataTable',
fields: [
{
label: '',
name: 'CustomerSubsPacksSNs.id'
}, {
label: '@(lblo.lblServiceNumbers):', //cdr formats and price lists don't show ticked when opening editor
name: 'CustomerSubsPacksSNs[].id', //SNs
type: "checkbox"
}
]
});
return editor;
}
How do I reference editor2 correctly? The form opens but ajax method CRUDCustomerSubsPacksSNs never gets hit when form opens. Browser console does not throw any errors. Thanks.
This question has an accepted answers - jump to answer
Answers
Clarification: the code for CRUDCustomerSubsPacksSNs loads a series of values from one table as a series of tick boxes and ticks some of these using values from another table. DT gets loaded via a different ajax method. How can I call the data from CRUDCustomerSubsPacksSNs when the DT code gets loaded on page display?
Code for DT:
The code above actually looks spot on to me. Could you give me a link to the page question so I can take a look at it and trace through why the second Editor isn't submitting please?
Thanks,
Allan
Hi
Thanks.
It is submitting when I click save but I need the form to be populated 1st with those values from that other table (CustomerVoiceCLI below) as a series of tick boxes.
The DT shows service charges and is loaded from ajax method CRUDCustomerSubsPacks. With the 2nd editor, the user can see what phone numbers are associated with the each service charge. The ajax method is CRUDCustomerSubsPacksSNs. The ticked values of numbers associated with the service charge come from table CustomerSubsPacksSNs. The tick boxes shows all numbers that can be associated with the service charge and get they values from CustomerSubsPacks CustomerVoiceCLI.
How can I get Editor to make a pass to the server just as I click the custom button so the tick boxes (CustomerVoiceCLI.CLI via CustomerVoiceCLI.id) and ticked values (CustomerSubsPacksSNs.SNID) are shown ?
Server code of CRUDCustomerSubsPacksSNs:
Many thanks Allan.
I've got a blog post for that . It's slightly different from what you are looking for, but similar enough that I think it it is relevant here - it makes a call to the server when the button is pressed and then triggers editing. In your case that would all be the same, but rather than refreshing the data in the table, use
val()
to set the value of fields based on the data you send back.Allan
Hi
Thanks but does this refresh the data for the DT or populate the 2nd editor? I think the latter. This bit:
How can I get Editor to make a pass to the server just as I click the custom button so the tick boxes (CustomerVoiceCLI.CLI via CustomerVoiceCLI.id) and ticked values (CustomerSubsPacksSNs.SNID) are shown ?
is on the 2nd editor. The pass Editor needs to make is to populate data on the 2nd editor form. Thanks.
It refreshes the data for the DT which is then used for the Editor.
You wouldn't have Editor do that. Your custom button would need to call
$.ajax()
(or similar) to get the data you need. You can then populate the values into the DataTable, and trigger editing, or the other way around if you prefer.Allan
Hi
The data shown by the 2nd editor is different from that used by the 1st editor. The 1st editor is the one used for editing the data shown by the DT. The 2nd editor shows competely different data. The user selects a row in the DT and can edit the data in the DT using the 1st editor. Its like if the DT was showing data for oranges, their sizes and weights. The 1st editor enables you to modify these values but via the 2nd editor the data shown is for (eg) something completely different like when these oranges were ordered (w/ fields like order date, employee,...).The 2nd editor would need to show lists of employees, date field for order date,...The 1st editor shows fields for weight, size of oranges,...Its just an example.
In my case the 1st editor shows service charges, cost of charge,...This is listed in the DT. But the 2nd editor shows phone numebrs linked to each service charge.
"It refreshes the data for the DT which is then used for the Editor."
The 2nd editor should not refresh the DT. The user selects a line and the 2nd editor opens via a cstom button with all the user's phone numbers and they select phone numbers linked w/ each service charge that was clicked. The DT does not list phone numbers but service charges. Thanks.
Okay - I'm with you now. Thanks for the clarification.
The second Editor - does it write to a different database table? With its own id column? If so, is that a simple left join it is doing, or is it a one-to-many relationship?
If it is just one-to-one or even all in a single db row, then you could just load all of the data needed into the host table and selectively show the fields in each of the Editor instances like here.
Allan
Hi
Thanks.
"The second Editor - does it write to a different database table?" Yes
"With its own id column?" Yes
"If so, is that a simple left join it is doing, or is it a one-to-many relationship?" The latter.
"You could just load all of the data needed into the host table and selectively show the fields in each of the Editor instances like here." The data to show on the 2nd editor is not the same as that shown on the DT and not the same data but showing different columns. It's taken from an entirely different db table. That table has a foreign key which corresponds to the phone numbers in the db table used for the DT.
I'm still not clear how I can make a pass to the server to show the underlining data (from a different table than the db table used for the DT) the user can select (those customer phone numbers). Thanks.
I will try and see if I can simply iterate through these phone numbers via checkboxes and an opts: and source property in the editor using a razor c# list. Then the user clicks the phone numbers he wants and saves the selection. This is then sent to the server.
Sorry, I think I now get what you meant: load all data via the same server method including the phone numbers and show the 2 types of data on their editor forms. Will try that.
Seems to work. Thanks again for the insight.
Awesome. Good to know you've got it working.
Allan