updating a dropdown list in the second page is failing

updating a dropdown list in the second page is failing

gstevegsteve Posts: 4Questions: 0Answers: 0
edited June 2012 in General
[thanks a lot for providing this wonderful plugin]

Hi all,

I'm populating the data result as a datatable - and it is paginated and spreads across two pages.
[it contains checkbox and dropdown list as well]

And i've implemented the functionality to get the selected checked row, and other details.

what i'm trying to do is:
I have a value that is to be updated as selected value in the tables selected records dropdown list - and I have the required row/column index as well.
And i'm updating using td:eq(columnIndex).. and so

what happens is:
The selected row in the first page which is visible currently to the user - gets updated properly, but the selected row s' respective dropdown list value which is in the second page is not getting updated.

it'll be very grateful if anybody can provide me a solution for this and also point me the mistake i'm doing here.

Replies

  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    Can you post any code or a sample? If your data source is AJAX I would check that the event handler for your drop downs is .on() or .live()
  • gstevegsteve Posts: 4Questions: 0Answers: 0
    Hi snarf - thanks for your response

    let me update the steps i'm doing and the reference code snips - for better explanation,

    1. every record has a checkbox as a first column, and last column as a drop down list values, populated from DB source - this is in .net MVC pattern and I do have a selectlist option to fill in the values
    2. if i select a couple or more records from data table using the check box, it picks the common dropdown values available for the selected records and populates in a seperate dropdown box[say DDLf] outside the grid.
    3. Now I can select a value in DDLf dropdown which is not by default selected in the datatable dropdown values and click a button
    4. and on click, the dropdown values in the table for the selected records - gets updated with the DDLf selected values.

    the above case is working when the selected record is on the first page, but if any selected records are present in 2nd or later pages, and currently page 1 is selected - these are not getting updated..

    the script i'm using is like -

    $('#DDLfBtn').click(function () {
    var fillVal = $('#DDLf').val());
    $("input:checked", dataTable.fnGetNodes()).each(function () {
    var rowIndex; var colIndex; //get respective column/row index for the checked records and manipulate the same to get actual column cell index

    $('#gridTbl td:eq(' + colIndex + ') select[name=dtDDL] option[value=' + fillVal + ']').attr('selected', 'selected');
    });
    });

    the above code doesn't update the records in other pages... but if i sort the records and bring the same to first page and try update, it works fine

    Please share your inputs on how to achieve this
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    So, if I am understanding correctly a user might check some boxes on multiple pages and then you want rows updated based on all values checked?

    You could store IDs as each checkbox is clicked and then go through all your table data to make alterations using http://datatables.net/api#fnGetData . However, if your data source is server side you could use something like this example: http://datatables.net/release-datatables/examples/server_side/select_rows.html
  • gstevegsteve Posts: 4Questions: 0Answers: 0
    Hi Snarf..

    just one clarification - using fnGetData I can only get the data of the cell right?
    But my intention is to update the cell [which is indeed a dropdown list change of selected value]..

    if my understanding on your comment is wrong - kindly correct me...
  • gstevegsteve Posts: 4Questions: 0Answers: 0
    another clarification - can I use fnUpdate to update a particular dropdown list column values selected value? any sample code/pointers will be of great help
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    Under purpose fnGetData "Get the data for the whole table, an individual row or an individual cell based on the provided parameters." " If mRow is undefined, then the data for all rows is returned."

    You should then be able to update the data you need to with fnUpdate
This discussion has been closed.