How to get data from datatables from container class

How to get data from datatables from container class

ronald.putronald.put Posts: 3Questions: 0Answers: 0
edited June 2013 in DataTables 1.9
Hi,
I'm working on a page with two Datatables. This page can Create, Edit and Delete records. Creating works... Editing and deleting NOT. This Page contains a container class:
[code]

var invoice = new Invoice
{
Invoices = new List(),
Records = new List()
};

public class InvoiceNumber
{
static int _nextId = 1;

public InvoiceNumber()
{
Id = _nextId++;
}
public int Id { get; set; }
public String Number { get; set; }

}

public class InvoiceRecord
{
private static int _nextIndex = 1;
public InvoiceRecord()
{
Index = _nextIndex++.ToString(CultureInfo.InvariantCulture);
}
public String Index { get; set; }
public string Description { get; set; }
public string Country { get; set; }
public bool Removable { get; set; }
}

[/code]

Datatable on yhe page:

[code]


@ViewBag.Title



Index
Description
Contry
Removable



@foreach (var item in Model.Records)
{

@item.Index
@item.Description
@item.Country
@item.Removable

}


Create | Edit | Delete


[/code]

On the page I have this (Part of) Script: (I THINK THIS IS THE PROBLEM AREA :( )
[code]

//---------------------------------------------------------------------------
// Add a click handler for the edit row
//---------------------------------------------------------------------------
$('#edit').click(function () {
//Get the existing values for the selected row
var anSelected = fnGetSelected(oTable);
var rowdata = $('#' + anSelected[0]).closest('tr').children('td');
//Initialize the form
$('#index').val($.trim(rowdata.eq(0).text()));
$('#description').val($.trim(rowdata.eq(1).text()));
$('#country').val($.trim(rowdata.eq(2).text()));
$('#removable').val($.trim(rowdata.eq(3).text()));
//Open the dialog
$('#dialog-edit').dialog({ title: 'Edit' });
$('#dialog-edit').dialog('open');
});
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Add a click handler for the delete row
//---------------------------------------------------------------------------
$('#delete').click(function () {
var anSelected = fnGetSelected(oTable);
var rowdata = $('#' + anSelected[0]).closest('tr').children('td');
alert("Delete " + anSelected[0].innerHTML);
alert("index=" + anSelected[0].cells[0].innerHTML +
"desc=" + anSelected[0].cells[1].innerHTML +
"country=" + anSelected[0].cells[2].innerHTML); //"" +
//"remv=" + anSelected[0].cells[3].innerHTML); //rowdata.eq(0).text());
alert("Name=" + anSelected[0].cells[0].innerHTML); //rowdata.eq(0).text());
$('#delete-index').val(anSelected[0].cells[0].innerHTML); //.replace('row-', ''));
$('#delete-description').val(anSelected[0].cells[1].innerHTML); //.html($.trim(rowdata.eq(1).text()));
$('#delete-country').val(anSelected[0].cells[2].innerHTML); //.html($.trim(rowdata.eq(1).text()));
//$('#delete-removable').val(anSelected[0].cells[3].innerHTML); //.html($.trim(rowdata.eq(1).text()));
//Open the dialog
$('#dialog-delete').dialog('open');
});
//---------------------------------------------------------------------------


[/code]

And these forms:

[code]

<!-- Form for Editing invoice -->







Description






Country



Nederland
Belgie
Duitsland














<!-- Form for deleting record -->


Are you sure you want to delete the record:

"-"




[/code]

The problem is the values of delete-index and delete-description in the ajax-delete-form are not filled in the $('#delete').click(function () {. Why is the question.

How can I change this to have the values set in the right way???

Ronald.
This discussion has been closed.