Facundo Posted January 21 Share Posted January 21 (edited) I have this part of code where I show data in the table: <?php foreach ($pedidos as $dato) { $codigoPedido = $dato['Codigo_pedido']; $razonSocialCliente = $dato['Razon_social']; $tipoPedido = $dato['Tipo_pedido']; $nombreEmpleado = $dato['NombreEmpleado']; $estadoPedido = $dato['Estado_pedido']; $fechaPedido = $dato['Fecha']; $descripcionProductos = explode('<br>', $dato['DescripcionProductos']); $cantidadProductos = explode(' ', $dato['CantidadProductos']); $precioTotal = $dato['PrecioTotal']; $numProductos = count($descripcionProductos); if (count($cantidadProductos) !== $numProductos) { continue; } ?> <tr> <td rowspan="<?php echo $numProductos ?>"><?php echo $codigoPedido ?></td> <td rowspan="<?php echo $numProductos ?>"><?php echo $razonSocialCliente ?></td> <td rowspan="<?php echo $numProductos ?>"><?php echo $tipoPedido ?></td> <td rowspan="<?php echo $numProductos ?>"><?php echo $nombreEmpleado ?></td> <td rowspan="<?php echo $numProductos ?>"><?php echo $estadoPedido ?></td> <td rowspan="<?php echo $numProductos ?>"><?php echo $fechaPedido ?></td> <td><?php echo $descripcionProductos[0] ?></td> <td><?php echo $cantidadProductos[0] ?></td> <?php $primerProductoPrecio = obtenerPrecioProductoPedido($codigoPedido, $descripcionProductos[0]); ?> <td><?php echo $primerProductoPrecio ?></td> <td rowspan="<?php echo $numProductos ?>"> <a href="borrarPedido.php?id=<?php echo $codigoPedido ?>" onclick='return test_click();' class="btn btn-danger"><i class="fas fa-user-minus"></i></a> <a href="actualizarPedido.php?id=<?php echo $codigoPedido ?>" class="btn btn-info"><i class="fas fa-pen"></i></a> <a href="agregarremito.php?id=<?php echo $codigoPedido ?>" class="btn btn-info"><i class="fas fa-bars"></i></a> </td> </tr> <?php for ($i = 1; $i < $numProductos; $i++) { ?> <tr> <td><?php echo $descripcionProductos[$i] ?></td> <td><?php echo $cantidadProductos[$i] ?></td> <?php $productoPrecio = obtenerPrecioProductoPedido($codigoPedido, $descripcionProductos[$i]); ?> <td><?php echo $productoPrecio ?></td> </tr> <?php } ?> <?php } ?> </tbody> I need help because in the part where I add more than one data in a row, it makes the filter, pagination and search disappear Edited January 22 by requinix please use the Code <> button when posting code Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/ Share on other sites More sharing options...
mac_gyver Posted January 21 Share Posted January 21 the links you produce need to start with a copy of any existing $_GET data (so that the original $_GET data is unchanged), set the relevant element(s) in the copy of the data, such as the id element, build the query-string part of the URLs using php's http_build_query(), then produce the link. this will propagate any existing filter, pagination, search, ... terms in the links. Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614278 Share on other sites More sharing options...
Facundo Posted January 21 Author Share Posted January 21 sorry, I do not understand. I understand that the pagination, filter, and search disappear because I have more than one product in my order (I tried deleting the counter and the pagination, filter, and search appear) Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614280 Share on other sites More sharing options...
mac_gyver Posted January 21 Share Posted January 21 we have no idea what you see in front of you. you need to post what result you are getting and what result you expect, for both the case where you have some counter in the code and when you don't. Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614281 Share on other sites More sharing options...
Facundo Posted January 21 Author Share Posted January 21 My table shows an order, but when an order is created with more than one product, the filtering, search and pagination options disappear. I want these options to not disappear while maintaining the ability to show more than one product in the order. Here is the complete code: https://live.datatables.net/hedazavu/1/edit Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614282 Share on other sites More sharing options...
mac_gyver Posted January 21 Share Posted January 21 so, you actually have a jquery dataTable problem? the dataTable coding assumes that each row has the same significance. any column sorting and pagination is based on the literal rows of data. i suspect that as soon as you put a rowspan with more then one row, that it produces javascript errors. you can check in the browser's developer tools console tab. the question becomes, what are you trying to accomplish? if you want to list all the orders, with column sorting, pagination, and searching, you would only output the unique/one-time information about each order. if someone finds an order that they want to see the details of, they would click on a link and, for example, open a dialog popup with the item details in it. you might (untested) be able to use the jquery dataTable show extra/detailed information api - see this link - https://datatables.net/examples/api/row_details.html If you want to instead be able to do column sorting, pagination, and searching for both order information and item information, forget about the rowspan and just repeat the common information in each row. Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614288 Share on other sites More sharing options...
ginerjm Posted January 22 Share Posted January 22 I've taken the OP's original presentation of his code and made it a bit more readable for those of us who don't see what the attempt here is. Isn't this below a bit more readable as well as understandable? foreach ($pedidos as $dato) { $codigoPedido = $dato['Codigo_pedido']; $razonSocialCliente = $dato['Razon_social']; $tipoPedido = $dato['Tipo_pedido']; $nombreEmpleado = $dato['NombreEmpleado']; $estadoPedido = $dato['Estado_pedido']; $fechaPedido = $dato['Fecha']; $descripcionProductos = explode('<br>', $dato['DescripcionProductos']); $cantidadProductos = explode('', $dato['CantidadProductos']); $precioTotal = $dato['PrecioTotal']; $numProductos = count($descripcionProductos); if (count($cantidadProductos) !== $numProductos) continue; echo " <tr> <td rowspan='$numProductos'>$codigoPedido</td> <td rowspan='$numProductos'>$razonSocialCliente</td> <td rowspan='$numProductos'>$tipoPedido</td> <td rowspan='$numProductos'>$nombreEmpleado</td> <td rowspan='$numProductos'>$estadoPedido</td> <td rowspan='$numProductos'>$fechaPedido</td> <td>{$descripcionProductos[0]}</td> <td>{$cantidadProductos[0]}</td> "; $primerProductoPrecio = obtenerPrecioProductoPedido($codigoPedido, $descripcionProductos[0]); echo " <td>$primerProductoPrecio</td> <td rowspan='$numProductos'> <a href='borrarPedido.php?id=$codigoPedido' onclick='return test_click();' class='btn btn-danger'><i class='fas fa-user-minus'></i></a> <a href='actualizarPedido.php?id=$codigoPedido' class='btn btn-info'><i class='fas fa-pen'></i></a> <a href='agregarremito.php?id=$codigoPedido' class='btn btn-info'><i class='fas fa-bars'></i></a> </td> </tr> "; for ($i = 1; $i < $numProductos; $i++) { echo " <tr> <td>{$descripcionProductos[$i]}</td> <td>{$cantidadProductos[$i]}</td> "; $productoPrecio = obtenerPrecioProductoPedido($codigoPedido, $descripcionProductos[$i]); echo " <td>$productoPrecio</td> </tr> "; } } echo "</tbody>"; Now - what is the problem here? Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614300 Share on other sites More sharing options...
Facundo Posted January 22 Author Share Posted January 22 hi ginerjm, The problem is that the pagination, search and filter of the datatable disappear, I found that the error is thanks to this: </tr> <?php for ($i = 1; $i < $numProductos; $i++) { ?> <tr> <td><?php echo $descripcionProductos[$i] ?></td> <td><?php echo $cantidadProductos[$i] ?></td> <?php $productoPrecio = obtenerPrecioProductoPedido($codigoPedido, $descripcionProductos[$i]); ?> <td><?php echo $productoPrecio ?></td> </tr> <?php } ?> <?php } ?> </tbody> I'm going to see what mac_gyver said maybe you have a solution Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614303 Share on other sites More sharing options...
ginerjm Posted January 22 Share Posted January 22 I see no effort in this piece code that does any of that. Care to enlighten me as to how that is being accomplished? And please stop writing code like this. Way too complicated and completely unnecessary. Please look at how I rewrote your post to be clearer and it does not unnecessarily switch in and out of php mode. If you don't wish to do that then I will bow out now and let you continue Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614315 Share on other sites More sharing options...
Strider64 Posted January 23 Share Posted January 23 That sure seems like a strange way in doing pagination. In my opinion the data should be come from a database table and broken down to something like the following -> // Grab the current page the user is on if (isset($_GET['page']) && !empty($_GET['page'])) { $current_page = urldecode($_GET['page']); } else { $current_page = 1; } $per_page = 2; // Total number of records to be displayed: // Grab Total Pages $total_pages = $cms->total_pages($total_count, $per_page); /* Grab the offset (page) location from using the offset method */ /* $per_page * ($current_page - 1) */ $offset = $cms->offset($per_page, $current_page); // Figure out the Links that you want the display to look like $links = new Links($current_page, $per_page, $total_count, $category); // Finally grab the records that are actually going to be displayed on the page $records = $cms->page($per_page, $offset, 'cms', $category); that way all you have to do is format. the HTML using CSS -> <main class="main_container" itemprop="mainContentOfPage"> <?php foreach ($records as $record) { $imagePath = htmlspecialchars($record['image_path'], ENT_QUOTES, 'UTF-8'); $heading = htmlspecialchars($record['heading'], ENT_QUOTES, 'UTF-8'); $content = htmlspecialchars($record['content'], ENT_QUOTES, 'UTF-8'); echo '<div class="image-header">'; echo '<img src="' . $imagePath . '" title="' . $heading . '" alt="' . $heading . '">'; echo '</div>'; echo '<h1>' . $heading . '</h1>'; echo '<p>' . nl2br($content) . '</p>'; echo '<br><hr><br>'; } ?> </main> The above is just an example, but if you breakdown the HTML/Code in smaller sections it's easier to read & debug. There are a lot of good pagination tutorials online. Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614327 Share on other sites More sharing options...
mac_gyver Posted January 23 Share Posted January 23 the basic jquery dataTable coding is only usable up to a few hundred rows of data, because of the time it takes to send that much data/markup to the client and how much time it takes to manipulate that much data in the client. once you have a lot of real-world data, you need to switch to use server-side processing, where the dataTable is just the User Interface (UI) and the actual work of column sorting, pagination, and searching is done on the server. only the data needed to 'draw' the current page is output to the client. see this link - https://datatables.net/examples/server_side/index.html in any case, if you want to do something like search and find all the orders that use an item, you will need to list all the items in the orders, repeating the common order data in the columns without using rowspans. Quote Link to comment https://forums.phpfreaks.com/topic/317645-my-datatable-does-not-show-filtering-pagination-and-search-please-help-me/#findComment-1614332 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.