On change of quantity I am calling jquery ajax as shown below. I am problem when at bottom of the
On change of quantity I am calling jquery ajax as shown below. I am problem when at bottom of the
ganesh09
Posts: 7Questions: 1Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Answers
When I am at the bottom of the page and when I change the quantity & moves to next quantity in next row with mouse click my page moves to the top of the page. How to keep my cursor on that quantity textbox clicked and how to keep page from scrolling to top?
below is the code.
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Its difficult to visualize what is happening with your code snippets. Please provide a link to your page or a test case replicating the issue so we can try out your solution to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Problem is when datatable Qty column textbox on change event is called when we click on next qty textbox. In on change event it calls dt.ajax.reload( null, false ) and cursor which was highlighting on second row disappears. Same things happen when user is at bottom of the page then not only focus on qty column is lost but also the page scrolls to top. User needs find on which row is was working on..
I tried to fix this by calling below line in on change event
$(this).find("td:eq(7) input[type='text']").focus();
but it is not working.
Sounds like you will need to determine which text box has focus and in the
ajax.reload()
callback function set the focus back to that input.Maybe the problem is that you have multiple ID's that are the same:
I'm assuming this input is in each row. ID's are to be unique on the page. Maybe fixing this will help. Take a look at this delegated events example for the best practice way to create events.
Kevin
No it not because of <input type="text" id="quantity'. $row['Id'] .'"
Now textbox id is unique. But error still remains.
can i call something like below and send row number to it to set focus.
table = $('#example').DataTable(); table.ajax.reload( function ( json ) { $(
//setfocus();
$(row[7]).find("td:eq(7) input[type='text']").focus();
} );
row[7]
in the callback function is likely undefined and so won't work. You can userow().node()
to get the node of the desired row.Sorry I assumed that lines 50-62 were the row inputs you show in you screenshot. To avoid confusion please provide a test case showing the issues you are having. You can use one of the JS BIN Ajax examples here for the
ajax.reload()
.Kevin
Sounds like you might be using PHP to output an event listener combo for every input? What I'd do is add a delegated event listener (as Kevin mentioned) for each plus icon and each minus icon (which you can do with CSS selectors), then get the parent element of the icon, and inside that parent, find the input. Then increment or decrement the found value as needed.
Thus you have a reusable component.
The extra step would be to just have your PHP output the input element, and then loop over each input adding the +/- icons for each with Javascript. That could then be used anywhere you need on your site.
Allan
Thanks Allan and Kevin.
see my code below. I now kept textbox only to show what problem I am facing.
Only problem is onchange event ajax perform some calculation and then reloads the datatable. Then my page scroll to top and my focus or cursor from textbox that I last clicked is lost.
On this jquery function i am facing problem
$(document).on('change', '.myTextBoxes', function(e){)
I will try to use JS BIN examples laer.
please find the code below.
$(document).ready(function(){
}); //DOCREADY//////////////
/////////////////
//qtyupdate change
$(document).on('change', '.myTextBoxes', function(e){
});
foreach($result as $row) {
}
$output =array(
"draw" => intval($_POST["draw"]),
"recordsTotal" =>count_all_data($db),
"recordsFiltered" => $number_filter_row,
"data" => $data
);
Do you have a need to reload the table on change? I'm not clear on why you are doing that?
Allan
because I pulling updated rows from database and it seems to working correctly if change the value and click other next textbox. my page does move to top.
But I will also try to set the values with reloading the datatable.
How will get row index change event.
want to set value to column oTable.cell(rowIndex, 13).data("$100.00");
The
cell().data()
API is a client side processing method. Since you have server side processing enabledcell().data()
won't do anything. You will need to update the server DB and refresh the data viaajax.reload()
like you are doing now.Kevin